import logging

from logging.handlers import RotatingFileHandler


def setup_logger(name: str, level: int = logging.INFO, log_file: str = "logs.log") -> logging.Logger:
    """
    Set up a logger with a rotating file handler.

    :param name: Name of the logger.
    :param level: Logging level, e.g., logging.INFO.
    :param log_file: File path for the log file.
    :return: Configured logger.
    """

    logger = logging.getLogger(name)
    logger.setLevel(level)
    logger.propagate = False

    # Create handlers
    c_handler = logging.StreamHandler()  # Console handler
    f_handler = RotatingFileHandler(log_file, maxBytes=1024 * 1024 * 5, backupCount=5)  # File handler with rotation

    # Create formatters and add it to handlers
    c_format = logging.Formatter("%(name)s - %(levelname)s - %(message)s")
    f_format = logging.Formatter(
        "%(asctime)s - %(name)s - %(levelname)s - %(message)s",
        datefmt="%Y-%m-%d %H:%M:%S",
    )
    c_handler.setFormatter(c_format)
    f_handler.setFormatter(f_format)

    # Add handlers to the logger
    logger.addHandler(c_handler)
    logger.addHandler(f_handler)

    return logger
