rizer.misc.logging#

Logging setup helpers for simulation entry-point scripts.

Attributes#

Functions#

configure_logging(→ None)

Configure console logging for a simulation entry-point script.

add_log_file_handler(→ logging.FileHandler)

Also persist logs to log_file, independently of the console's level.

get_case_logger(→ logging.LoggerAdapter)

Return a logger that prefixes every message with case_name.

Module Contents#

rizer.misc.logging.logger#
rizer.misc.logging.configure_logging(level: str | int = 'INFO') None#

Configure console logging for a simulation entry-point script.

Call this once, near the top of a script (e.g. scripts/2T0D_constant_mass_NRP/run_2T0D_constant_mass_simulation.py) – never from inside a per-case/per-segment function such as run_constant_mass_nrp_simulation(), which must not reconfigure global logging state itself (doing so used to reset the root logger to WARNING on every call, silently swallowing later INFO-level setup logs in a loop that calls it many times, e.g. the sensitivity-analysis sweep).

The root logger itself is left at DEBUG (permissive): level only restricts what the console handler shows. This is deliberate, so that calling add_log_file_handler() afterwards persists the full log regardless of level – e.g. logging_level: WARNING quiets the terminal without losing INFO/DEBUG detail from the saved run.log.

Parameters:

level (str or int, optional) – Console logging level (e.g. "INFO", "DEBUG", "WARNING", or a logging level constant). Default "INFO".

rizer.misc.logging.add_log_file_handler(log_file: str | pathlib.Path, level: str | int = logging.DEBUG) logging.FileHandler#

Also persist logs to log_file, independently of the console’s level.

Call once configure_logging() has already run and the run’s case folder exists (see create_case_folder()), so every run gets a durable, structured log next to its saved results and inputs.

Parameters:
  • log_file (str or pathlib.Path) – Path to the log file to create/append to (e.g. case_path / "run.log").

  • level (str or int, optional) – Logging level for this handler. Default logging.DEBUG (i.e. capture everything the loggers emit) – deliberately not tied to configure_logging()’s console level, so the saved log stays complete even when the terminal is quieted down.

Returns:

The handler that was added to the root logger, so a caller that creates a new one per case (e.g. the sensitivity-analysis sweep) can remove/close the previous one without searching logging.getLogger().handlers.

Return type:

logging.FileHandler

rizer.misc.logging.get_case_logger(case_name: str) logging.LoggerAdapter#

Return a logger that prefixes every message with case_name.

Intended for a loop that runs many cases in one process (e.g. run_2T0D_sensitivity_analysis_electron_density.py’s per-reaction sweep): pass the result as run_constant_mass_nrp_simulation()’s logger argument so every log line from that case – including the ones emitted by whatever it calls – is tagged, and a combined log file can be filtered per case.

Parameters:

case_name (str) – Identifier prefixed to every log message (e.g. the reaction equation or case folder name).

Returns:

Adapter wrapping this module’s logger.

Return type:

logging.LoggerAdapter