nirs4all.core.logging package
Submodules
- nirs4all.core.logging.config module
- nirs4all.core.logging.context module
BranchContextLogContextRunStateRunState.run_idRunState.run_nameRunState.projectRunState.start_timeRunState.current_phaseRunState.branch_stackRunState.source_contextRunState.stack_contextRunState.extraRunState.branch_depthRunState.branch_pathRunState.branch_stackRunState.current_branchRunState.current_phaseRunState.extraRunState.projectRunState.run_idRunState.run_nameRunState.source_contextRunState.stack_contextRunState.start_time
SourceContextStackContextget_current_state()get_run_id()inject_context()
- nirs4all.core.logging.events module
EventTypeEventType.ARTIFACTEventType.BRANCH_COMPAREEventType.BRANCH_ENTEREventType.BRANCH_EXITEventType.BUILDEventType.COLLECTEventType.COMPLETEEventType.CONFIG_LOADEventType.DEDUPLICATEEventType.ENVIRONMENTEventType.ERROREventType.EXPANDEventType.LEAKAGE_CHECKEventType.LOADEventType.METRICEventType.MODELEventType.PREDICTIONSEventType.PROGRESSEventType.PRUNEEventType.REPORTEventType.SKIPEventType.SOURCE_CONCATEventType.SOURCE_PROCESSEventType.STARTEventType.STEPEventType.TRAIN_METAEventType.TRANSFORMEventType.VALIDATEEventType.WARNING
LogEventLogEvent.timestampLogEvent.levelLogEvent.phaseLogEvent.event_typeLogEvent.messageLogEvent.run_idLogEvent.statusLogEvent.branch_nameLogEvent.branch_pathLogEvent.branch_indexLogEvent.source_indexLogEvent.source_nameLogEvent.duration_msLogEvent.metricsLogEvent.extraLogEvent.branch_indexLogEvent.branch_nameLogEvent.branch_pathLogEvent.duration_msLogEvent.event_typeLogEvent.extraLogEvent.levelLogEvent.messageLogEvent.metricsLogEvent.phaseLogEvent.run_idLogEvent.source_indexLogEvent.source_nameLogEvent.statusLogEvent.timestampLogEvent.to_dict()LogEvent.to_json()
PhaseStatus
- nirs4all.core.logging.formatters module
- nirs4all.core.logging.handlers module
- nirs4all.core.logging.progress module
EvaluationProgressMultiLevelProgressProgressBarProgressBar.COLOR_CYANProgressBar.COLOR_DIMProgressBar.COLOR_GREENProgressBar.COLOR_RESETProgressBar.COLOR_YELLOWProgressBar.EMPTY_ASCIIProgressBar.EMPTY_UNICODEProgressBar.FILLED_ASCIIProgressBar.FILLED_UNICODEProgressBar.__enter__()ProgressBar.__exit__()ProgressBar.close()ProgressBar.set_description()ProgressBar.set_postfix()ProgressBar.start()ProgressBar.update()ProgressBar.wrap()
ProgressConfigProgressConfig.bar_widthProgressConfig.show_percentageProgressConfig.show_countProgressConfig.show_elapsedProgressConfig.show_etaProgressConfig.show_rateProgressConfig.refresh_rateProgressConfig.use_unicodeProgressConfig.use_colorsProgressConfig.bar_widthProgressConfig.refresh_rateProgressConfig.show_countProgressConfig.show_elapsedProgressConfig.show_etaProgressConfig.show_percentageProgressConfig.show_rateProgressConfig.use_colorsProgressConfig.use_unicode
SpinnerProgressconfigure_progress()evaluation_progress()progress_bar()spinner()
Module contents
Unified logging system for nirs4all.
This module provides a structured, configurable logging infrastructure that replaces all print() statements with proper logging. It supports:
Human-readable console output optimized for scientists
Machine-parseable file logging for automation
Context tracking for runs, phases, branches, and sources
ASCII-safe output for HPC/cluster environments
Progress throttling to avoid terminal flooding
TTY-aware progress bars with multi-level support
- Usage:
>>> from nirs4all.core.logging import get_logger, configure_logging, LogContext >>> >>> # Configure at application startup >>> configure_logging(verbose=1, use_unicode=True) >>> >>> # Get logger in each module >>> logger = get_logger(__name__) >>> >>> # Use context for run tracking >>> with LogContext(run_id="my-experiment"): ... logger.info("Starting analysis") ... with LogContext.branch("snv", index=0, total=4): ... logger.success("SNV preprocessing complete")
- Progress Bars:
>>> from nirs4all.core.logging import ProgressBar, EvaluationProgress >>> >>> # Simple progress bar >>> with ProgressBar(total=100, description="Processing") as pbar: ... for i in range(100): ... pbar.update(1) >>> >>> # ML-specific evaluation progress >>> with EvaluationProgress(total_pipelines=42, metric_name="RMSE") as progress: ... for pipeline in pipelines: ... score = evaluate(pipeline) ... progress.update(score=score)
See also
nirs4all.core.logging.configfor configuration detailsnirs4all.core.logging.contextfor context managementnirs4all.core.logging.formattersfor output formattingnirs4all.core.logging.progressfor progress bars
- class nirs4all.core.logging.BranchContext(name: str, path: list[str] = <factory>, index: int | None = None, total: int | None = None, parent: str | None = None, depth: int = 0)[source]
Bases:
objectContext for a branch in the pipeline.
- class nirs4all.core.logging.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.ConsoleFormatter(use_colors: bool = True, show_elapsed: bool = False, use_unicode: bool = True)[source]
Bases:
FormatterHuman-readable console formatter for nirs4all logs.
Produces clean, scannable output optimized for terminal viewing with proper indentation for hierarchy, status symbols, and optional elapsed time.
- COLORS = {'BLUE': '\x1b[34m', 'BOLD': '\x1b[1m', 'CYAN': '\x1b[36m', 'DIM': '\x1b[2m', 'GREEN': '\x1b[32m', 'MAGENTA': '\x1b[35m', 'RED': '\x1b[31m', 'RESET': '\x1b[0m', 'WHITE': '\x1b[37m', 'YELLOW': '\x1b[33m'}
- LEVEL_COLORS = {'CRITICAL': 'RED', 'DEBUG': 'DIM', 'ERROR': 'RED', 'INFO': 'RESET', 'WARNING': 'YELLOW'}
- class nirs4all.core.logging.EvaluationProgress(total_pipelines: int, metric_name: str = 'score', higher_is_better: bool = False, description: str = 'Evaluating pipelines', config: ProgressConfig | None = None, disable: bool = False)[source]
Bases:
objectSpecialized progress tracker for pipeline evaluation.
Provides ML-specific tracking with best score updates and automatic milestone reporting.
Example
>>> progress = EvaluationProgress( ... total_pipelines=42, ... metric_name="RMSE", ... higher_is_better=False ... ) >>> >>> with progress: ... for pipeline in pipelines: ... score = evaluate(pipeline) ... progress.update(score=score, pipeline_name="SavGol+PLS")
- __enter__() EvaluationProgress[source]
Enter context manager.
- update(score: float | None = None, pipeline_name: str | None = None, n: int = 1) bool[source]
Update progress with optional score.
- Parameters:
score – Score for the completed pipeline.
pipeline_name – Name of the pipeline.
n – Number of pipelines completed.
- Returns:
True if this was a new best score.
- class nirs4all.core.logging.EventType(value)[source]
-
Event types within phases.
- ARTIFACT = 'artifact'
- BRANCH_COMPARE = 'branch_compare'
- BRANCH_ENTER = 'branch_enter'
- BRANCH_EXIT = 'branch_exit'
- BUILD = 'build'
- COLLECT = 'collect'
- COMPLETE = 'complete'
- CONFIG_LOAD = 'config_load'
- DEDUPLICATE = 'deduplicate'
- ENVIRONMENT = 'environment'
- ERROR = 'error'
- EXPAND = 'expand'
- LEAKAGE_CHECK = 'leakage_check'
- LOAD = 'load'
- METRIC = 'metric'
- MODEL = 'model'
- PREDICTIONS = 'predictions'
- PROGRESS = 'progress'
- PRUNE = 'prune'
- REPORT = 'report'
- SKIP = 'skip'
- SOURCE_CONCAT = 'source_concat'
- SOURCE_PROCESS = 'source_process'
- START = 'start'
- STEP = 'step'
- TRAIN_META = 'train_meta'
- TRANSFORM = 'transform'
- VALIDATE = 'validate'
- WARNING = 'warning'
- class nirs4all.core.logging.FileFormatter[source]
Bases:
FormatterFile formatter for human-readable log files.
Produces timestamped, leveled output suitable for file storage and later analysis.
- class nirs4all.core.logging.JsonFormatter(run_id: str | None = None)[source]
Bases:
FormatterJSON Lines formatter for machine-readable log files.
Produces one JSON object per line for easy parsing by log aggregation systems like ELK, Loki, etc.
- class nirs4all.core.logging.LogContext(run_id: str | None = None, run_name: str | None = None, project: str | None = None, **extra: Any)[source]
Bases:
objectContext manager for run-level logging context.
Provides a context manager that sets up run state and can be used to track the current run, phase, branches, sources, etc.
Example
>>> with LogContext(run_id="my-experiment", project="protein"): ... logger.info("Starting analysis") ... with LogContext.branch("snv", index=0, total=4): ... logger.info("Processing SNV branch")
- __enter__() LogContext[source]
Enter the context, setting up run state.
- __exit__(exc_type: Any, exc_val: Any, exc_tb: Any) None[source]
Exit the context, restoring previous state.
- static branch(name: str, index: int | None = None, total: int | None = None, parent: str | None = None) Generator[BranchContext, None, None][source]
Context manager for tracking branch execution.
- Parameters:
name – Branch name.
index – Branch index (0-based).
total – Total number of branches at this level.
parent – Parent branch name (for nested branches).
- Yields:
BranchContext for the current branch.
- static phase(phase: Phase) Generator[None, None, None][source]
Context manager for tracking the current phase.
- Parameters:
phase – The phase being entered.
- Yields:
None
- static source(name: str, index: int | None = None, total: int | None = None) Generator[SourceContext, None, None][source]
Context manager for tracking source processing in multi-source pipelines.
- Parameters:
name – Source name.
index – Source index (0-based).
total – Total number of sources.
- Yields:
SourceContext for the current source.
- static stack(n_branches: int, meta_model: str | None = None, branch_sources: list[str] | None = None) Generator[StackContext, None, None][source]
Context manager for tracking stacking operations.
- Parameters:
n_branches – Number of branches being stacked.
meta_model – Meta-model name/description.
branch_sources – List of branch names being stacked.
- Yields:
StackContext for the stacking operation.
- class nirs4all.core.logging.LogEvent(timestamp: datetime, level: str, phase: Phase | None, event_type: EventType, message: str, run_id: str | None = None, status: Status | None = None, branch_name: str | None = None, branch_path: list[str] | None = None, branch_index: int | None = None, source_index: int | None = None, source_name: str | None = None, duration_ms: float | None = None, metrics: dict[str, ~typing.Any]=<factory>, extra: dict[str, ~typing.Any]=<factory>)[source]
Bases:
objectStructured log event for machine-readable logging.
- timestamp
Event timestamp.
- Type:
- phase
Current workflow phase.
- Type:
- event_type
Type of event within the phase.
- status
Event status indicator.
- Type:
- class nirs4all.core.logging.MultiLevelProgress(run_total: int | None = None, run_description: str = 'Run progress', config: ProgressConfig | None = None, disable: bool = False)[source]
Bases:
objectMulti-level progress tracking for nested operations.
Supports tracking progress at multiple levels: - Run level (overall run progress) - Pipeline level (pipeline evaluation within run) - Fold level (CV folds within pipeline) - Training level (epochs/batches within training)
Example
>>> progress = MultiLevelProgress( ... run_total=5, ... run_description="Evaluating datasets" ... ) >>> >>> with progress.run_level() as run_pbar: ... for dataset in datasets: ... with progress.pipeline_level(total=10) as pipe_pbar: ... for pipeline in pipelines: ... # evaluate ... pipe_pbar.update(1) ... run_pbar.update(1)
- fold_level(total: int, description: str = 'Cross-validation') ProgressBar[source]
Get fold-level progress bar.
- Parameters:
total – Total number of folds.
description – Description text.
- Returns:
ProgressBar for fold level.
- pipeline_level(total: int, description: str = 'Evaluating pipelines') ProgressBar[source]
Get pipeline-level progress bar.
- Parameters:
total – Total number of pipelines.
description – Description text.
- Returns:
ProgressBar for pipeline level.
- run_level(total: int | None = None, description: str | None = None) ProgressBar[source]
Get run-level progress bar.
- Parameters:
total – Override total (uses init value if None).
description – Override description.
- Returns:
ProgressBar for run level.
- training_level(total: int, description: str = 'Training') ProgressBar[source]
Get training-level progress bar.
- Parameters:
total – Total epochs or batches.
description – Description text.
- Returns:
ProgressBar for training level.
- class nirs4all.core.logging.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.
- class nirs4all.core.logging.NullHandler(level=0)[source]
Bases:
HandlerHandler that discards all log records.
Used when logging should be completely silent.
- class nirs4all.core.logging.Phase(value)[source]
-
Major workflow phases for high-level tracking.
- BRANCH = 'branch'
- COMPLETE = 'complete'
- DATA = 'data'
- EVALUATE = 'evaluate'
- EXPORT = 'export'
- GENERATE = 'generate'
- INIT = 'init'
- PREDICT = 'predict'
- SOURCE = 'source'
- SPLIT = 'split'
- STACK = 'stack'
- TRAIN = 'train'
- class nirs4all.core.logging.ProgressBar(total: int, description: str = '', config: ProgressConfig | None = None, leave: bool = True, disable: bool = False, unit: str = 'it', file: Any = None, initial: int = 0, ncols: int | None = None)[source]
Bases:
objectTTY-aware progress bar for tracking iterations.
Provides a clean progress display that automatically adapts to terminal capabilities. Falls back to periodic line-based updates when not in a TTY.
Example
>>> with ProgressBar(total=100, description="Processing") as pbar: ... for i in range(100): ... # do work ... pbar.update(1)
>>> # Or with iterator >>> for item in ProgressBar.wrap(items, description="Processing"): ... # do work with item
- COLOR_CYAN = '\x1b[36m'
- COLOR_DIM = '\x1b[2m'
- COLOR_GREEN = '\x1b[32m'
- COLOR_RESET = '\x1b[0m'
- COLOR_YELLOW = '\x1b[33m'
- EMPTY_ASCII = '-'
- EMPTY_UNICODE = '░'
- FILLED_ASCII = '#'
- FILLED_UNICODE = '█'
- __enter__() ProgressBar[source]
Enter context manager.
- set_description(description: str) None[source]
Update description text.
- Parameters:
description – New description text.
- set_postfix(**kwargs: Any) None[source]
Set postfix values (shown after bar).
- Parameters:
**kwargs – Key-value pairs to display.
- class nirs4all.core.logging.ProgressConfig(bar_width: int = 30, show_percentage: bool = True, show_count: bool = True, show_elapsed: bool = True, show_eta: bool = True, show_rate: bool = False, refresh_rate: float = 0.1, use_unicode: bool = True, use_colors: bool = True)[source]
Bases:
objectConfiguration for progress bar display.
- class nirs4all.core.logging.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.RunState(run_id: str, run_name: str | None = None, project: str | None = None, start_time: datetime = <factory>, current_phase: Phase | None = None, branch_stack: list[BranchContext] = <factory>, source_context: SourceContext | None = None, stack_context: StackContext | None = None, extra: dict[str, ~typing.Any]=<factory>)[source]
Bases:
objectState for a single run.
- start_time
Run start timestamp.
- Type:
- current_phase
Current workflow phase.
- Type:
- branch_stack
Stack of branch contexts (for nesting).
- source_context
Current source context (if any).
- Type:
- stack_context
Current stacking context (if any).
- Type:
- branch_stack: list[BranchContext]
- property current_branch: BranchContext | None
Get the current (innermost) branch context.
- source_context: SourceContext | None = None
- stack_context: StackContext | None = None
- class nirs4all.core.logging.SourceContext(name: str, index: int | None = None, total: int | None = None)[source]
Bases:
objectContext for a source in multi-source pipelines.
- class nirs4all.core.logging.SpinnerProgress(description: str = 'Processing', use_unicode: bool = True, use_colors: bool = True, disable: bool = False)[source]
Bases:
objectSpinner for indeterminate progress indication.
Use when the total number of items is unknown.
Example
>>> with SpinnerProgress("Loading data") as spinner: ... data = load_large_dataset() ... spinner.update("Parsing...") ... parsed = parse(data)
- FRAMES_ASCII = ['|', '/', '-', '\\']
- FRAMES_UNICODE = ['⠋', '⠙', '⠹', '⠸', '⠼', '⠴', '⠦', '⠧', '⠇', '⠏']
- __enter__() SpinnerProgress[source]
Enter context manager.
- class nirs4all.core.logging.StackContext(n_branches: int, meta_model: str | None = None, branch_sources: list[str] = <factory>)[source]
Bases:
objectContext for stacking operations.
- class nirs4all.core.logging.Status(value)[source]
-
Status indicators for log messages.
- ERROR = 'error'
- IN_PROGRESS = 'in_progress'
- SKIPPED = 'skipped'
- STARTING = 'starting'
- SUCCESS = 'success'
- WARNING = 'warning'
- class nirs4all.core.logging.Symbols(use_unicode: bool = True)[source]
Bases:
objectSymbol system for log output with ASCII/Unicode modes.
Provides consistent symbols for status indicators, hierarchy markers, and other visual elements in log output.
- class nirs4all.core.logging.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}
- nirs4all.core.logging.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.configure_progress(bar_width: int = 30, show_percentage: bool = True, show_count: bool = True, show_elapsed: bool = True, show_eta: bool = True, show_rate: bool = False, refresh_rate: float = 0.1, use_unicode: bool = True, use_colors: bool = True) None[source]
Configure global progress bar settings.
- Parameters:
bar_width – Width of progress bar in characters.
show_percentage – Show percentage completion.
show_count – Show current/total count.
show_elapsed – Show elapsed time.
show_eta – Show estimated time remaining.
show_rate – Show items per second.
refresh_rate – Minimum seconds between display updates.
use_unicode – Use Unicode characters for bar.
use_colors – Use ANSI colors.
- nirs4all.core.logging.evaluation_progress(total_pipelines: int, metric_name: str = 'score', higher_is_better: bool = False, **kwargs: Any) EvaluationProgress[source]
Create an evaluation progress tracker.
- Parameters:
total_pipelines – Total pipelines to evaluate.
metric_name – Name of optimization metric.
higher_is_better – True if higher is better.
**kwargs – Additional arguments.
- Returns:
EvaluationProgress instance.
- nirs4all.core.logging.format_duration(seconds: float) str[source]
Format a duration in seconds to human-readable string.
- Parameters:
seconds – Duration in seconds.
- Returns:
Human-readable duration string (e.g., “2m 5.9s”, “1h 23m 45s”).
- nirs4all.core.logging.format_number(value: float | int, precision: int = 3) str[source]
Format a number for display.
Uses thousands separators for large integers and appropriate precision for floats.
- Parameters:
value – Number to format.
precision – Decimal precision for floats.
- Returns:
Formatted number string.
Format the run footer block.
- Parameters:
status – Final run status.
duration_seconds – Total run duration in seconds.
best_pipeline – Description of best pipeline (optional).
metrics – Final metrics dict (optional).
use_unicode – If True, use Unicode symbols.
- Returns:
Formatted footer block string.
- nirs4all.core.logging.format_run_header(run_name: str, start_time: datetime, environment_info: dict[str, str] | None = None, reproducibility_info: dict[str, str] | None = None, use_unicode: bool = True) str[source]
Format the run header block.
- Parameters:
run_name – Name of the run.
start_time – Run start timestamp.
environment_info – Optional environment details (Python version, etc.).
reproducibility_info – Optional reproducibility info (seed, git hash, etc.).
use_unicode – If True, use Unicode symbols.
- Returns:
Formatted header block string.
- nirs4all.core.logging.format_table(headers: list[str], rows: list[list[str]], use_unicode: bool = True) str[source]
Format a simple ASCII table.
- Parameters:
headers – Column headers.
rows – Table rows (list of lists).
use_unicode – Unused, kept for API consistency.
- Returns:
Formatted table string.
- nirs4all.core.logging.get_config() LogConfig[source]
Get the current logging configuration.
- Returns:
Current LogConfig instance.
- nirs4all.core.logging.get_current_state() RunState | None[source]
Get the current run state.
- Returns:
Current RunState or None if not in a run context.
- nirs4all.core.logging.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")
- nirs4all.core.logging.get_run_id() str | None[source]
Get the current run ID.
- Returns:
Current run ID or None if not in a run context.
- nirs4all.core.logging.is_configured() bool[source]
Check if logging has been configured.
- Returns:
True if configure_logging() has been called.
- nirs4all.core.logging.progress_bar(total: int, description: str = '', **kwargs: Any) ProgressBar[source]
Create a progress bar.
- Parameters:
total – Total number of items.
description – Description text.
**kwargs – Additional ProgressBar arguments.
- Returns:
ProgressBar instance.
- nirs4all.core.logging.reset_logging() None[source]
Reset logging configuration to defaults.
This clears all handlers and resets the configuration. Useful for testing. Ensures file handlers are properly closed to avoid issues on Windows where open file handles prevent file deletion.
- nirs4all.core.logging.spinner(description: str = 'Processing', **kwargs: Any) SpinnerProgress[source]
Create a spinner for indeterminate progress.
- Parameters:
description – Description text.
**kwargs – Additional SpinnerProgress arguments.
- Returns:
SpinnerProgress instance.