"""
Logging utilities for Sentinel.
"""

import logging
from logging.handlers import RotatingFileHandler
from pathlib import Path


def setup_logger(log_file_path: Path) -> logging.Logger:
    """
    Configure and return the main Sentinel logger.

    Args:
        log_file_path: Path of the persistent log file.

    Returns:
        Configured Sentinel logger.
    """
    logger = logging.getLogger("Sentinel")
    logger.setLevel(logging.INFO)

    if logger.handlers:
        return logger

    formatter = logging.Formatter(
        "%(asctime)s | %(levelname)s | %(message)s"
    )

    console_handler = logging.StreamHandler()
    console_handler.setFormatter(formatter)

    file_handler = RotatingFileHandler(
        filename=log_file_path,
        maxBytes=5_000_000,
        backupCount=5,
        encoding="utf-8",
    )
    file_handler.setFormatter(formatter)

    logger.addHandler(console_handler)
    logger.addHandler(file_handler)

    return logger