Logging Utilitiesο
The logging module provides comprehensive logging functionality with automatic configuration and file rotation support.
Module Overviewο
Modern logging system for siege_utilities. Provides structured logging with proper configuration management.
Functionsο
- siege_utilities.core.logging.init_logger(name, log_to_file=False, log_dir='logs', level='INFO', max_bytes=5000000, backup_count=5, shared_log_file=None)[source]
Initialize a logger with specific configuration.
- Parameters:
name β Logger name
log_to_file β Whether to log to file
log_dir β Directory for log files
level β Log level
max_bytes β Max file size before rotation
backup_count β Number of backup files
shared_log_file β Path to shared log file
- Returns:
Configured logger instance
- siege_utilities.core.logging.get_logger(name=None)[source]
Get a logger instance.
- siege_utilities.core.logging.log_debug(message, logger_name=None)[source]
Log a debug message.
- siege_utilities.core.logging.log_info(message, logger_name=None)[source]
Log an info message.
- siege_utilities.core.logging.log_warning(message, logger_name=None)[source]
Log a warning message.
- siege_utilities.core.logging.log_error(message, logger_name=None)[source]
Log an error message.
- siege_utilities.core.logging.log_critical(message, logger_name=None)[source]
Log a critical message.
- siege_utilities.core.logging.parse_log_level(level)[source]
Convert a string or numeric level into a logging level constant.
- Parameters:
level β String (βDEBUGβ, βINFOβ, etc.) or int (10, 20, etc.)
- Returns:
Logging level constant
Usage Examplesο
Basic logging setup:
import siege_utilities
# Initialize logger with custom configuration
siege_utilities.init_logger(
name='my_app',
log_to_file=True,
log_dir='logs',
level='DEBUG'
)
# Use logging functions directly
siege_utilities.log_info("Application started")
siege_utilities.log_debug("Debug information")
siege_utilities.log_warning("Warning message")
siege_utilities.log_error("Error occurred")
Advanced logging with file rotation:
# Configure with file rotation
siege_utilities.init_logger(
name='production_app',
log_to_file=True,
log_dir='logs',
level='INFO',
max_bytes=10000000, # 10MB
backup_count=10
)
# Get logger instance for custom handling
logger = siege_utilities.get_logger()
logger.handlers[0].setFormatter(
logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
)
Unit Testsο
The logging module has comprehensive test coverage:
β
test_core_logging.py - All logging functionality tests pass
Test Coverage:
- Logger initialization and configuration
- All log level functions (debug, info, warning, error, critical)
- File logging and rotation
- Log level parsing
- Logger instance retrieval
Test Results: All logging tests pass successfully with 100% coverage.