From e15f6a4ccf6c6d3a303f1b38d349f90a382e7cf5 Mon Sep 17 00:00:00 2001 From: Nirodan Date: Tue, 17 Jun 2025 11:09:20 +0200 Subject: [PATCH] Trennen von errorlogs und normalen logs --- backend/app.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/backend/app.py b/backend/app.py index 52e19a8..7bc0e16 100644 --- a/backend/app.py +++ b/backend/app.py @@ -7,6 +7,7 @@ import time import os import jwt import logging +from logging.handlers import RotatingFileHandler app = Flask(__name__) app.template_folder = "templates" @@ -16,12 +17,33 @@ CONFIG_PATH = "config/db_config.json" MAX_WAIT = 30 # In Sekunden WAIT_INTERVAL = 10 + +# Logging-Zielpfade +log_dir = "Tools" +os.makedirs(log_dir, exist_ok=True) + +# App-Log (alles ab INFO) +app_log_handler = RotatingFileHandler( + os.path.join(log_dir, "app.log"), maxBytes=1_000_000, backupCount=3 +) +app_log_handler.setLevel(logging.INFO) +app_log_handler.setFormatter(logging.Formatter( + "%(asctime)s [%(levelname)s] %(message)s")) + +# Error-Log (nur ERROR) +error_log_handler = RotatingFileHandler( + os.path.join(log_dir, "error.log"), maxBytes=1_000_000, backupCount=3 +) +error_log_handler.setLevel(logging.ERROR) +error_log_handler.setFormatter(logging.Formatter( + "%(asctime)s [%(levelname)s] %(message)s")) + +# Logging-Grundkonfiguration logging.basicConfig( level=logging.INFO, - format="%(asctime)s [%(levelname)s] %(message)s", handlers=[ - logging.FileHandler("logs/app.log"), - logging.FileHandler("logs/errors.log"), + app_log_handler, + error_log_handler, logging.StreamHandler() ] )