feat: add structured logging, CSV metadata headers, and CLI improvements
- New module: beta_spectrum/logging_utils.py - LoggingConfig dataclass with level, log_file, format options - setup_logging() one-shot configuration (opt-in for library use) - get_logger() for named child loggers - get_git_short_hash() for commit identification - _find_git_root() for repo detection - CLI enhancements (beta_spectrum/cli.py): - --verbose/-v (repeatable): -v=INFO, -vv=DEBUG - --quiet/-q: suppress all terminal output - --log-file PATH: append log to file - --dry-run: validate input, display resolved config, exit - --version: show package version - Replace print() with structured logging throughout - Handle KeyboardInterrupt gracefully - CSV metadata headers (BetaSpectrumAnalyzer.export_to_csv): - YAML-style # comments with version, timestamp, source, nuclide info - Corrections enabled, e_step, detector settings, git commit hash - Base class integration (SpectrumComponent): - Optional logger parameter for debug/info output (opt-in) - BetaSpectrum integration: - Optional logger parameter passed through from_config() - Detector logging in create_detector_from_config() - Convolution logging in convolve_with_detector() - Tests: tests/test_logging_utils.py (28 tests) - LoggingConfig, setup_logging, get_logger, git hash, CSV headers, CLI flags - Update TODO.md: mark B8 as complete, update Current Status
This commit is contained in:
+15
-2
@@ -1,6 +1,10 @@
|
||||
# base.py
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
import numpy as np
|
||||
|
||||
ArrayLike = np.ndarray
|
||||
@@ -8,12 +12,21 @@ ArrayLike = np.ndarray
|
||||
|
||||
class SpectrumComponent(ABC):
|
||||
"""
|
||||
Base class for multiplicative components of beta-spectrum
|
||||
Base class for multiplicative components of beta-spectrum.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
logger : logging.Logger, optional
|
||||
Logger instance for debug/info output. If None, logging is disabled.
|
||||
Opt-in design: components are silent by default for library use.
|
||||
"""
|
||||
|
||||
def __init__(self, logger: Optional["logging.Logger"] = None) -> None:
|
||||
self._logger = logger
|
||||
|
||||
@abstractmethod
|
||||
def __call__(self, W: ArrayLike) -> ArrayLike:
|
||||
"""
|
||||
Evaluate component at total energy W (in m_e units)
|
||||
Evaluate component at total energy W (in m_e units).
|
||||
"""
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user