"""Structured logging configuration.""" from __future__ import annotations import logging from typing import Any import structlog from .config import get_settings def configure_logging() -> None: """Configure structlog for JSON-like structured logs.""" settings = get_settings() logging.basicConfig(level=settings.log_level) logging.getLogger("azure").setLevel(logging.WARNING) logging.getLogger("azure.core").setLevel(logging.WARNING) logging.getLogger("azure.identity").setLevel(logging.WARNING) logging.getLogger("azure.core.pipeline.policies.http_logging_policy").setLevel( logging.WARNING ) structlog.configure( processors=[ structlog.processors.TimeStamper(fmt="iso"), structlog.processors.add_log_level, structlog.processors.StackInfoRenderer(), structlog.processors.format_exc_info, structlog.processors.JSONRenderer(), ], wrapper_class=structlog.make_filtering_bound_logger( logging.getLevelName(settings.log_level) ), cache_logger_on_first_use=True, ) def get_logger(**context: Any) -> structlog.BoundLogger: """Return a logger bound with optional context.""" return structlog.get_logger().bind(**context)