"""Structured logging.""" from __future__ import annotations import logging import sys from typing import Any import structlog from app.core.config import get_settings def configure_logging() -> None: s = get_settings() level = getattr(logging, s.log_level.upper(), logging.INFO) logging.basicConfig( format="%(message)s", stream=sys.stdout, level=level, ) structlog.configure( wrapper_class=structlog.make_filtering_bound_logger(level), processors=[ structlog.contextvars.merge_contextvars, structlog.processors.add_log_level, structlog.processors.TimeStamper(fmt="iso"), structlog.processors.StackInfoRenderer(), structlog.dev.set_exc_info, structlog.processors.JSONRenderer(), ], logger_factory=structlog.PrintLoggerFactory(), cache_logger_on_first_use=True, ) def get_logger(name: str | None = None, **initial: Any) -> structlog.stdlib.BoundLogger: return structlog.get_logger(name, **initial)