📝 "Refactor: Update log rotation correction in logging update to app.log files

This commit is contained in:
2025-05-10 23:26:14 +02:00
parent 9939db731b
commit 40c3f6d9b4
5 changed files with 88 additions and 54 deletions

Binary file not shown.

12
app.py
View File

@@ -382,6 +382,18 @@ def admin_required(f):
return f(*args, **kwargs) return f(*args, **kwargs)
return decorated_function return decorated_function
# Hilfsfunktion zur Fehlerbehandlung in API-Endpunkten
def handle_api_exception(func):
"""Decorator für API-Endpunkte zur einheitlichen Fehlerbehandlung"""
@wraps(func)
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
except Exception as e:
# Log und API-Fehler zurückgeben
return ErrorHandler.handle_exception(e, is_api_request=True)
return wrapper
@login_manager.user_loader @login_manager.user_loader
def load_user(id): def load_user(id):
# Verwende session.get() anstelle von query.get() für SQLAlchemy 2.0 Kompatibilität # Verwende session.get() anstelle von query.get() für SQLAlchemy 2.0 Kompatibilität

View File

@@ -25,3 +25,9 @@
2025-05-10 23:17:04,727 INFO: Anwendung gestartet [in C:\Users\TTOMCZA.EMEA\Dev\website\app.py:76] 2025-05-10 23:17:04,727 INFO: Anwendung gestartet [in C:\Users\TTOMCZA.EMEA\Dev\website\app.py:76]
2025-05-10 23:17:06,698 INFO: Anwendung gestartet [in C:\Users\TTOMCZA.EMEA\Dev\website\app.py:76] 2025-05-10 23:17:06,698 INFO: Anwendung gestartet [in C:\Users\TTOMCZA.EMEA\Dev\website\app.py:76]
2025-05-10 23:17:06,698 INFO: Anwendung gestartet [in C:\Users\TTOMCZA.EMEA\Dev\website\app.py:76] 2025-05-10 23:17:06,698 INFO: Anwendung gestartet [in C:\Users\TTOMCZA.EMEA\Dev\website\app.py:76]
2025-05-10 23:23:26,898 INFO: Anwendung gestartet [in C:\Users\TTOMCZA.EMEA\Dev\website\app.py:76]
2025-05-10 23:23:28,862 INFO: Anwendung gestartet [in C:\Users\TTOMCZA.EMEA\Dev\website\app.py:76]
2025-05-10 23:23:28,862 INFO: Anwendung gestartet [in C:\Users\TTOMCZA.EMEA\Dev\website\app.py:76]
2025-05-10 23:24:45,296 INFO: Anwendung gestartet [in C:\Users\TTOMCZA.EMEA\Dev\website\app.py:76]
2025-05-10 23:24:47,176 INFO: Anwendung gestartet [in C:\Users\TTOMCZA.EMEA\Dev\website\app.py:76]
2025-05-10 23:24:47,176 INFO: Anwendung gestartet [in C:\Users\TTOMCZA.EMEA\Dev\website\app.py:76]

View File

@@ -9,9 +9,19 @@ import sqlite3
parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) parent_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, parent_dir) sys.path.insert(0, parent_dir)
from app import app, db_path # Vermeidung zirkulärer Importe - importiere nur die Modelle und DB-Objekt
from models import db, User, Thought, MindMapNode, Category from models import db, User, Thought, MindMapNode, Category
def get_db_path():
"""Ermittelt den Pfad zur Datenbankdatei"""
db_dir = os.path.join(parent_dir, 'database')
if not os.path.exists(db_dir):
os.makedirs(db_dir)
return os.path.join(db_dir, 'systades.db')
# Datenbank-Pfad
db_path = get_db_path()
def test_database_connection(): def test_database_connection():
"""Test if the database exists and can be connected to.""" """Test if the database exists and can be connected to."""
try: try:
@@ -37,7 +47,8 @@ def test_database_connection():
def test_models(): def test_models():
"""Test if all models are properly defined and can be queried.""" """Test if all models are properly defined and can be queried."""
with app.app_context(): # Import app here to avoid circular import
from flask import current_app
try: try:
print("\nTesting User model...") print("\nTesting User model...")
user_count = User.query.count() user_count = User.query.count()
@@ -65,7 +76,6 @@ def test_models():
def print_database_stats(): def print_database_stats():
"""Print database statistics.""" """Print database statistics."""
with app.app_context():
try: try:
stats = [] stats = []
stats.append(("Users", User.query.count())) stats.append(("Users", User.query.count()))
@@ -97,6 +107,9 @@ def run_all_tests():
if not test_database_connection(): if not test_database_connection():
success = False success = False
# Import app here to avoid circular import
from app import app
with app.app_context():
# Test models # Test models
print("\n2. Testing database models...") print("\n2. Testing database models...")
if not test_models(): if not test_models():
@@ -117,4 +130,7 @@ def run_all_tests():
return success return success
if __name__ == "__main__": if __name__ == "__main__":
# Import app here to avoid circular import
from app import app
with app.app_context():
run_all_tests() run_all_tests()