sagaphone/backend/app/logging_config.py

26 lines
721 B
Python
Raw Normal View History

"""Logging setup for the backend.
Follows the project's output contract: all log output goes to stderr,
level controlled via the LOG_LEVEL env var (default INFO). This is server
logging, not the request/response payload that stays in FastAPI's
responses.
"""
from __future__ import annotations
import logging
import os
import sys
def configure_logging() -> None:
level_name = os.environ.get("LOG_LEVEL", "INFO").upper()
level = getattr(logging, level_name, logging.INFO)
handler = logging.StreamHandler(sys.stderr)
handler.setFormatter(logging.Formatter("%(asctime)s %(levelname)-5s %(name)s: %(message)s"))
root = logging.getLogger()
root.setLevel(level)
root.handlers = [handler]