nirs4all.core.logging.config module
Configuration and initialization for nirs4all logging.
This module provides the main configuration interface for the logging system, including the configure_logging() function and related utilities.
- class nirs4all.core.logging.config.Nirs4allLogger(name: str, level: int = 0)[source]
Bases:
LoggerExtended logger with nirs4all-specific methods.
Provides convenience methods for structured logging with status indicators, progress reporting, and context-aware logging.
- artifact(artifact_type: str, path: str | Path, size_bytes: int | None = None, **kwargs: Any) None[source]
Log an artifact save.
- Parameters:
artifact_type – Type of artifact (“model”, “report”, “predictions”).
path – Path where artifact was saved.
size_bytes – Size of artifact in bytes.
**kwargs – Additional logging kwargs.
- makeRecord(name: str, level: int, fn: str, lno: int, msg: object, args: tuple, exc_info: Any, func: str | None = None, extra: dict[str, Any] | None = None, sinfo: str | None = None) LogRecord[source]
Create a LogRecord with context injection.
Overrides the standard makeRecord to inject run context.
- metric(name: str, value: float, scope: str = 'cv', fold: int | None = None, pipeline: str | None = None, **kwargs: Any) None[source]
Log a metric value.
- Parameters:
name – Metric name (e.g., “RMSE”, “R2”).
value – Metric value.
scope – Metric scope (“cv”, “train”, “test”, “fold”).
fold – Fold number (for per-fold metrics).
pipeline – Pipeline identifier.
**kwargs – Additional logging kwargs.
- phase_complete(phase: Phase, duration_seconds: float | None = None, **extra_fields: Any) None[source]
Log the completion of a workflow phase.
- Parameters:
phase – The phase that completed.
duration_seconds – Phase duration in seconds.
**extra_fields – Additional context fields.
- phase_start(phase: Phase, **extra_fields: Any) None[source]
Log the start of a workflow phase.
- Parameters:
phase – The phase being started.
**extra_fields – Additional context fields.
- progress(operation: str, current: int, total: int, best_score: float | None = None, is_new_best: bool = False, extra_fields: dict[str, Any] | None = None, **kwargs: Any) None[source]
Log a progress update.
Progress messages are automatically throttled to avoid flooding.
- Parameters:
operation – Name of the operation in progress.
current – Current step number.
total – Total number of steps.
best_score – Current best score (optional).
is_new_best – If True, this update reports a new best result.
extra_fields – Additional context fields.
**kwargs – Additional logging kwargs.
Log the run footer block.
- Parameters:
status – Final run status.
duration_seconds – Total run duration.
best_pipeline – Best pipeline description.
metrics – Final metrics.
- run_header(run_name: str, environment_info: dict[str, str] | None = None, reproducibility_info: dict[str, str] | None = None) None[source]
Log the run header block.
- Parameters:
run_name – Name of the run.
environment_info – Environment details (Python version, etc.).
reproducibility_info – Reproducibility info (seed, git hash, etc.).
- starting(msg: str, *args: Any, extra_fields: dict[str, Any] | None = None, **kwargs: Any) None[source]
Log a starting/beginning message.
- Parameters:
msg – Log message.
*args – Message formatting args.
extra_fields – Additional context fields.
**kwargs – Additional logging kwargs.
- nirs4all.core.logging.config.configure_logging(verbose: int = 1, log_file: bool = False, log_dir: str | Path | None = None, log_format: str = 'pretty', use_unicode: bool | None = None, use_colors: bool | None = None, show_elapsed: bool = False, show_progress: bool = True, show_progress_bar: bool = True, json_output: bool = False, run_id: str | None = None, max_log_runs: int = 100, max_log_age_days: int | None = 30, max_log_bytes: int | None = None, compress_logs: bool = True) None[source]
Configure the nirs4all logging system.
This function should be called once at application startup to set up logging. Subsequent calls will reconfigure the logging system.
- Parameters:
verbose – Verbosity level (0=WARNING, 1=INFO, 2=DEBUG, 3=TRACE).
log_file – If True, write logs to workspace/logs/ directory.
log_dir – Directory for log files (used if log_file=True).
log_format – Output format: “pretty”, “minimal”, or “json”.
use_unicode – Use Unicode symbols (auto-detected if None).
use_colors – Use ANSI colors (auto-detected if None).
show_elapsed – Show elapsed time since run start.
show_progress – Show progress updates for long operations.
show_progress_bar – Show TTY-aware progress bars.
json_output – Also write JSON Lines log file.
run_id – Override run ID (auto-generated if not provided).
max_log_runs – Maximum number of run logs to keep (count-based rotation).
max_log_age_days – Maximum age of logs in days (None to disable).
max_log_bytes – Maximum log file size before rotation (None to disable).
compress_logs – Whether to gzip rotated log files.
- nirs4all.core.logging.config.get_config() LogConfig[source]
Get the current logging configuration.
- Returns:
Current LogConfig instance.
- nirs4all.core.logging.config.get_logger(name: str) Nirs4allLogger[source]
Get a logger for the specified module.
This is the primary interface for obtaining a logger in nirs4all modules. The logger is automatically configured with context injection and nirs4all-specific methods.
- Parameters:
name – Logger name, typically __name__.
- Returns:
Configured Nirs4allLogger instance.
Example
>>> from nirs4all.core.logging import get_logger >>> logger = get_logger(__name__) >>> logger.info("Processing data")