first
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
"""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)
|
||||
Reference in New Issue
Block a user