"""Configure backend settings for logging."""

from loguru import logger
import sys
# Keep configuration setup explicit so runtime behavior is easy to reason about.



def setup_logging(level: str = "INFO"):
    """Handle setup logging."""

    # Keep configuration setup explicit so runtime behavior is easy to reason about.
    logger.remove()

    # Keep configuration setup explicit so runtime behavior is easy to reason about.
    logger.add(
        sys.stdout,
        level=level,
        format="<green>{time:YYYY-MM-DD HH:mm:ss}</green> | <level>{level: <8}</level> | <cyan>{name}</cyan>:<cyan>{function}</cyan>:<cyan>{line}</cyan> - <level>{message}</level>",
        colorize=True
    )

    # Keep configuration setup explicit so runtime behavior is easy to reason about.
    logger.add(
        "logs/app_{time:YYYY-MM-DD}.log",
        level=level,
        format="{time:YYYY-MM-DD HH:mm:ss} | {level: <8} | {name}:{function}:{line} - {message}",
        rotation="00:00",
        retention="7 days",
        compression="zip"
    )

    return logger
