This commit is contained in:
2026-03-27 03:58:57 +08:00
commit 86eba27a24
38 changed files with 4074 additions and 0 deletions

41
app/logging_setup.py Normal file
View File

@@ -0,0 +1,41 @@
"""
app/logging_setup.py
Centralised logging configuration for the application.
"""
from __future__ import annotations
import logging
import sys
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from app.config import Settings
def configure_logging(settings: "Settings") -> None:
"""Configure root logger and suppress noisy third-party loggers."""
level = getattr(logging, settings.log_level.upper(), logging.INFO)
formatter = logging.Formatter(
fmt="%(asctime)s %(levelname)-8s %(name)s %(message)s",
datefmt="%Y-%m-%d %H:%M:%S",
)
handler = logging.StreamHandler(sys.stdout)
handler.setFormatter(formatter)
root = logging.getLogger()
root.setLevel(level)
# Avoid duplicate handlers if called multiple times
if not root.handlers:
root.addHandler(handler)
else:
root.handlers[0] = handler
# Quieten noisy third-party loggers
for noisy in ("uvicorn.access", "uvicorn.error", "httpx", "httpcore"):
logging.getLogger(noisy).setLevel(logging.WARNING)
logging.getLogger("uvicorn").setLevel(logging.INFO)