babylon.config.logging_config

Logging configuration for Babylon/Babylon.

Logging is the nervous system of the simulation. Every action must be traceable, every decision auditable.

This module provides: - setup_logging(): Single entry point for logging initialization - load_logging_config(): Load config from pyproject.toml - RotatingFileHandler for main and error-only logs - JSONFormatter for machine-parseable output - Console handler for human-readable output

Configuration Hierarchy (highest precedence first): 1. LOG_LEVEL environment variable (global override) 2. pyproject.toml [tool.babylon.logging] section 3. logging.yaml file (if exists) 4. Default hardcoded values

Functions

create_simulation_handler(simulation_id[, seed])

Create a file handler for a specific simulation run.

get_current_config()

Get the current logging configuration (for debugging/inspection).

load_logging_config([pyproject_path])

Load logging configuration from pyproject.toml.

setup_logging([config_path, default_level, ...])

Initialize the logging system.

Classes

LoggingConfig([default_level, ...])

Centralized logging configuration loaded from pyproject.toml.

class babylon.config.logging_config.LoggingConfig(default_level='INFO', console_level='INFO', file_level='DEBUG', modules=<factory>)[source]

Bases: object

Centralized logging configuration loaded from pyproject.toml.

Parameters:
default_level

Global default log level

console_level

Log level for console output

file_level

Log level for file output

modules

Per-module log level overrides

default_level: str = 'INFO'
console_level: str = 'INFO'
file_level: str = 'DEBUG'
modules: dict[str, str]
__init__(default_level='INFO', console_level='INFO', file_level='DEBUG', modules=<factory>)
Parameters:
Return type:

None

babylon.config.logging_config.load_logging_config(pyproject_path=None)[source]

Load logging configuration from pyproject.toml.

Parameters:

pyproject_path (Path | None) – Path to pyproject.toml. If None, searches for it.

Return type:

LoggingConfig

Returns:

LoggingConfig with settings from pyproject.toml or defaults.

The configuration is loaded from [tool.babylon.logging] section.

babylon.config.logging_config.setup_logging(config_path=None, default_level=None, pyproject_path=None)[source]

Initialize the logging system.

Parameters:
  • config_path (Path | None) – Path to a YAML logging configuration file. If None, uses pyproject.toml or default configuration.

  • default_level (str | None) – Override for the default log level.

  • pyproject_path (Path | None) – Path to pyproject.toml (optional, auto-detected).

Return type:

None

Configuration is loaded in this order (highest precedence first): 1. LOG_LEVEL environment variable 2. default_level parameter 3. pyproject.toml [tool.babylon.logging] section 4. logging.yaml file (if config_path provided) 5. Default values

The logging system is deterministic - given the same inputs, it produces the same outputs. No probabilistic behavior.

Handler hierarchy: - Console: Human-readable, INFO level (or configured level) - Main file (RotatingFileHandler): JSON Lines, DEBUG level, 10MB rotation - Error file (RotatingFileHandler): JSON Lines, ERROR only, 5MB rotation

babylon.config.logging_config.create_simulation_handler(simulation_id, seed=None)[source]

Create a file handler for a specific simulation run.

Creates a per-simulation log file for forensic analysis and replay.

Parameters:
  • simulation_id (str) – Unique identifier for the simulation.

  • seed (int | None) – Random seed used for the simulation (optional).

Return type:

RotatingFileHandler

Returns:

Configured RotatingFileHandler for the simulation log.

babylon.config.logging_config.get_current_config()[source]

Get the current logging configuration (for debugging/inspection).

Return type:

LoggingConfig

Returns:

LoggingConfig loaded from pyproject.toml.