Files
appfactory-portal/app/logging_config.py
T
JiriUhlir bd256d565c c
2026-06-17 12:47:53 +02:00

32 lines
904 B
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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)