"""Configure structlog for machine-readable live logs and readable development logs."""

import logging

import structlog

from app.config import AppMode


def configure_logging(app_mode: AppMode) -> None:
    """Install the process logging pipeline for the selected runtime mode."""
    logging.basicConfig(level=logging.INFO, format="%(message)s")
    renderer: structlog.types.Processor
    if app_mode is AppMode.LIVE:
        renderer = structlog.processors.JSONRenderer()
    else:
        renderer = structlog.dev.ConsoleRenderer(colors=False)
    structlog.configure(
        processors=[
            structlog.contextvars.merge_contextvars,
            structlog.processors.add_log_level,
            structlog.processors.TimeStamper(fmt="iso", utc=True),
            structlog.processors.StackInfoRenderer(),
            structlog.processors.format_exc_info,
            renderer,
        ],
        wrapper_class=structlog.make_filtering_bound_logger(logging.INFO),
        logger_factory=structlog.PrintLoggerFactory(),
        cache_logger_on_first_use=True,
    )
