"""Structured logging for AtoCore.""" import logging import atocore.config as _config import structlog _LOG_LEVELS = { "DEBUG": logging.DEBUG, "INFO": logging.INFO, "WARNING": logging.WARNING, "ERROR": logging.ERROR, } def setup_logging() -> None: """Configure structlog with JSON output.""" log_level = "DEBUG" if _config.settings.debug else "INFO" structlog.configure( processors=[ structlog.contextvars.merge_contextvars, structlog.processors.add_log_level, structlog.processors.TimeStamper(fmt="iso"), structlog.dev.ConsoleRenderer() if settings.debug else structlog.processors.JSONRenderer(), ], wrapper_class=structlog.make_filtering_bound_logger( _LOG_LEVELS.get(log_level, logging.INFO) ), context_class=dict, logger_factory=structlog.PrintLoggerFactory(), cache_logger_on_first_use=True, ) def get_logger(name: str) -> structlog.BoundLogger: """Get a named logger.""" return structlog.get_logger(name)