Trennen von errorlogs und normalen logs
This commit is contained in:
+25
-3
@@ -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()
|
||||
]
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user