Rolling Log Handler with Line-Based Trimming
Maintains a log file with a maximum of 5000 lines. When the limit is reached, the oldest lines (from the head) are removed to make room for new entries.
This ensures the log file never grows unbounded while preserving the most recent information for debugging and auditing.
Author: AZ1.AI INC (Hal Casteel) Framework: CODITECT License: MIT
File: rolling_log_handler.py
Classes
RollingLineFileHandler
Custom file handler that maintains a maximum number of lines.
Functions
setup_rolling_logger(log_file, logger_name, max_lines, console_level, file_level)
Setup a logger with rolling file handler and console output.
emit(record)
Emit a record, trimming old lines if necessary.
Usage
python rolling_log_handler.py