def redirect_logs(log_file: str) -> None:
    """Add file handler to logger and remove other handlers.

    This function sets up file-based logging by:
        - Creating a file handler for the specified log file
        - Setting a standard format for log messages
        - Removing all other handlers from existing loggers
        - Configuring warning capture

    Args:
        log_file: Path to the log file where messages will be written.
            Parent directories will be created if they don't exist.

    Example:
        >>> from pathlib import Path
        >>> log_path = Path("logs/app.log")
        >>> redirect_logs(str(log_path))  # doctest: +SKIP
        >>> import logging
        >>> logger = logging.getLogger(__name__)
        >>> logger.info("Test message")  # Message written to logs/app.log

    Note:
        - The log format includes timestamp, logger name, level and message
        - All existing handlers are removed from loggers to ensure logs only go
          to file
        - This function does not work well with multiprocessing - logs from
          child processes will not be redirected
        - The function captures Python warnings in addition to regular logs
    """
    Path(log_file).parent.mkdir(exist_ok=True, parents=True)
    logger_file_handler = logging.FileHandler(log_file)
    format_string = "%(asctime)s - %(name)s - %(levelname)s - %(message)s"
    logging.basicConfig(format=format_string, handlers=[logger_file_handler])
    logging.captureWarnings(capture=True)
    # remove other handlers from all loggers
    loggers = [logging.getLogger(name) for name in logging.root.manager.loggerDict]
    for _logger in loggers:
        _logger.handlers = [logger_file_handler]
Add file handler to logger and remove other handlers.

    This function sets up file-based logging by:
        - Creating a file handler for the specified log file
        - Setting a standard format for log messages
        - Removing all other handlers from existing loggers
        - Configuring warning capture

    Args:
        log_file: Path to the log file where messages will be written.
            Parent directories will be created if they don't exist.

    Example:
        >>> from pathlib import Path
        >>> log_path = Path("logs/app.log")
        >>> redirect_logs(str(log_path))  # doctest: +SKIP
        >>> import logging
        >>> logger = logging.getLogger(__name__)
        >>> logger.info("Test message")  # Message written to logs/app.log

    Note:
        - The log format includes timestamp, logger name, level and message
        - All existing handlers are removed from loggers to ensure logs only go
          to file
        - This function does not work well with multiprocessing - logs from
          child processes will not be redirected
        - The function captures Python warnings in addition to regular logs
    
src/anomalib/utils/logging.py