nirs4all.core.logging.handlers module
Custom log handlers for nirs4all logging.
This module provides specialized handlers for throttled progress updates, file rotation, and other custom logging behaviors.
- class nirs4all.core.logging.handlers.BufferedHandler(max_size: int = 1000)[source]
Bases:
HandlerHandler that buffers log records for batch processing.
Useful for collecting logs during a phase and outputting them together, e.g., for branch comparison summaries.
- emit(record: LogRecord) None[source]
Buffer the log record.
- Parameters:
record – Log record to buffer.
- class nirs4all.core.logging.handlers.NullHandler(level=0)[source]
Bases:
HandlerHandler that discards all log records.
Used when logging should be completely silent.
- class nirs4all.core.logging.handlers.RotatingRunFileHandler(log_dir: Path, run_id: str, max_runs: int = 100, max_age_days: int | None = 30, max_bytes: int | None = None, compress_rotated: bool = True, json_output: bool = False)[source]
Bases:
HandlerHandler that writes logs to run-specific files with rotation.
Creates a new log file for each run, with optional rotation to limit total log storage. Supports both count-based and age-based rotation policies.
- Features:
Separate log files per run
Count-based rotation (max_runs)
Age-based rotation (max_age_days)
Size-based rotation (max_bytes)
Optional gzip compression for rotated logs
Optional JSON Lines output
- emit(record: LogRecord) None[source]
Write log record to file(s).
- Parameters:
record – Log record to write.
- class nirs4all.core.logging.handlers.ThrottledHandler(base_handler: Handler, min_interval: float = 5.0)[source]
Bases:
HandlerHandler that throttles progress messages to avoid flooding.
Uses time-based and percentage-based throttling to limit progress updates while still reporting important milestones.
- MILESTONES = {10, 25, 50, 75, 90, 100}