added console logging

This commit is contained in:
2026-08-30 12:11:57 +02:00
parent c1d731f85d
commit bb80bb953c
4 changed files with 18 additions and 4 deletions
+13 -3
View File
@@ -35,15 +35,16 @@ class PrefixMiddleware:
def configure_logging(app: Flask) -> None:
log_path = app.config["LOG_FILE"]
log_path.parent.mkdir(parents=True, exist_ok=True)
formatter = logging.Formatter(
"%(asctime)s %(levelname)s %(name)s [%(threadName)s] %(message)s"
)
handler = RotatingFileHandler(
log_path,
maxBytes=app.config["LOG_MAX_BYTES"],
backupCount=app.config["LOG_BACKUP_COUNT"],
encoding="utf-8",
)
handler.setFormatter(logging.Formatter(
"%(asctime)s %(levelname)s %(name)s [%(threadName)s] %(message)s"
))
handler.setFormatter(formatter)
root = logging.getLogger()
root.setLevel(app.config["LOG_LEVEL"])
# Avoid duplicate handlers when an app factory is called repeatedly in tests.
@@ -57,6 +58,15 @@ def configure_logging(app: Flask) -> None:
else:
handler.close()
if app.config["LOG_CONSOLE"] and not any(
isinstance(item, logging.StreamHandler)
and not isinstance(item, logging.FileHandler)
for item in root.handlers
):
console = logging.StreamHandler()
console.setFormatter(formatter)
root.addHandler(console)
def uncaught_exception(exception_type, exception, traceback):
if issubclass(exception_type, KeyboardInterrupt):
return sys.__excepthook__(exception_type, exception, traceback)