Spaces:
Paused
Paused
| # filename: log_config.py | |
| """ | |
| Logging configuration module. | |
| This module sets up the global logging configuration and provides a function to retrieve loggers with the given name. | |
| """ | |
| import logging | |
| from logging.handlers import RotatingFileHandler | |
| # Configure the global logging settings | |
| log_formatter = logging.Formatter( | |
| fmt='%(asctime)s - %(name)s - %(levelname)s - %(message)s', | |
| datefmt='%Y-%m-%d %H:%M:%S' | |
| ) | |
| # File handler with rotation, set the rotation size to 5 MB | |
| file_handler = RotatingFileHandler('analysis_logs.log', maxBytes=5*10**6, backupCount=3) | |
| file_handler.setFormatter(log_formatter) | |
| # Stream handler | |
| stream_handler = logging.StreamHandler() | |
| stream_handler.setFormatter(log_formatter) | |
| # Setting up the root logger | |
| logging.basicConfig( | |
| level=logging.INFO, | |
| handlers=[file_handler, stream_handler] | |
| ) | |
| def get_logger(name: str) -> logging.Logger: | |
| """ | |
| Retrieve a logger with the given name. | |
| Args: | |
| name (str): The name of the logger to retrieve. | |
| Returns: | |
| logging.Logger: A logger configured with global settings. | |
| """ | |
| return logging.getLogger(name) | |
| # file: log_config.py (end) | |