31 lines
781 B
Python
31 lines
781 B
Python
"""Centralized logging setup.
|
|
|
|
Project rule: every error or unexpected state must reach the log. Never swallow
|
|
an exception silently. Secrets (access tokens, app secrets, appsecret_proof)
|
|
must NEVER be logged.
|
|
"""
|
|
import logging
|
|
import os
|
|
|
|
_LEVEL = os.getenv("LOG_LEVEL", "INFO").upper()
|
|
|
|
_configured = False
|
|
|
|
|
|
def configure_logging() -> None:
|
|
"""Configure root logging once. Safe to call multiple times."""
|
|
global _configured
|
|
if _configured:
|
|
return
|
|
logging.basicConfig(
|
|
level=_LEVEL,
|
|
format="%(asctime)s %(levelname)s %(name)s %(message)s",
|
|
)
|
|
_configured = True
|
|
|
|
|
|
def get_logger(name: str) -> logging.Logger:
|
|
"""Return a module logger. Use ``get_logger(__name__)``."""
|
|
configure_logging()
|
|
return logging.getLogger(name)
|