This commit is contained in:
JiriUhlir
2026-06-17 12:47:53 +02:00
parent 223f59d750
commit bd256d565c
8 changed files with 550 additions and 34 deletions
+31
View File
@@ -0,0 +1,31 @@
import logging
import os
_CONFIGURED = False
def configure_logging() -> None:
"""Jednotné logování portálu do stdout (zachytí uvicorn / docker logs).
Pravidlo projektu: žádné tiché selhání chyby a neočekávané stavy patří do logu.
Úroveň lze řídit přes PORTAL_LOG_LEVEL (výchozí INFO)."""
global _CONFIGURED
if _CONFIGURED:
return
level_name = (os.environ.get("PORTAL_LOG_LEVEL") or "INFO").upper()
level = getattr(logging, level_name, logging.INFO)
root = logging.getLogger()
if not root.handlers:
handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)s %(name)s: %(message)s"))
root.addHandler(handler)
root.setLevel(level)
_CONFIGURED = True
def get_logger(name: str) -> logging.Logger:
configure_logging()
return logging.getLogger(name)