Spaces:
Paused
Paused
File size: 1,153 Bytes
cb1a5c9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | # 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)
|