Logging#
Structured logging for SpectoPrep, built on structlog.
Call configure_logging() once at application/CLI entry to install the
processor chain, then obtain loggers anywhere with get_logger(). Library
modules only call get_logger(); they never configure logging at import
time, so importing SpectoPrep never mutates a host application’s logging setup.
Examples
>>> from spectoprep.logging import configure_logging, get_logger
>>> configure_logging(level="INFO")
>>> log = get_logger("example")
>>> log.info("cv_evaluated", rmse=0.12, r2=0.98)
- spectoprep.logging.configure_logging(level='INFO', json_logs=False, force=False)[source]#
Configure structlog and the standard-library logging bridge.
The
levelis always validated. If logging has already been configured (for example by an application entry point) this call becomes a no-op unlessforce=True, so a library component instantiated later never overrides an explicit application configuration.- Parameters:
level (str, default="INFO") – Minimum level name (“DEBUG”, “INFO”, “WARNING”, “ERROR”, “CRITICAL”).
json_logs (bool, default=False) – Emit newline-delimited JSON (machine-readable) when True, otherwise a colourised, human-readable console renderer.
force (bool, default=False) – Reconfigure even if logging was already configured.
- Raises:
ValueError – If
levelis not a recognised logging level name.- Return type:
None
- spectoprep.logging.get_logger(name=None)[source]#
Return a structlog logger.
This never configures logging as a side effect, so importing SpectoPrep stays inert. structlog returns a lazy proxy that binds to whatever configuration is active at first log call; if
configure_logging()was never called, structlog’s built-in defaults apply.