babylon.utils.log
Custom logging utilities for Babylon.
Logging is the nervous system of the simulation. Every action must be traceable, every decision auditable.
This module provides: - JSONFormatter: Dependency-free JSON Lines formatter - TRACE level: Ultra-verbose debugging (level=5) - LogContext: Context propagation for correlation IDs and tick numbers
Module Attributes
Ultra-verbose tracing level for deep debugging. |
Functions
Clear all log context fields. |
|
Get the current log context. |
|
|
Context manager for scoped log context. |
|
Set log context fields. |
Classes
|
Logging filter that injects context fields into LogRecords. |
|
JSON Lines formatter - zero external dependencies. |
- babylon.utils.log.TRACE: int = 5
Ultra-verbose tracing level for deep debugging.
NEVER enable in production. For materialist microscopy only.
- class babylon.utils.log.JSONFormatter(fmt=None, datefmt=None, style='%', validate=True, *, defaults=None)[source]
Bases:
FormatterJSON Lines formatter - zero external dependencies.
Produces machine-parseable JSONL output suitable for log aggregation. Each log record becomes a single JSON object on one line.
- Output format:
{“ts”:”2025-01-09T14:23:45.123Z”,”level”:”ERROR”,”logger”:”babylon.rag”,…}
Extra fields (tick, correlation_id, exception, etc.) are automatically included from the LogRecord’s __dict__.
- class babylon.utils.log.ContextAwareFilter(name='')[source]
Bases:
FilterLogging filter that injects context fields into LogRecords.
Automatically adds fields from the current log context (tick, simulation_id, correlation_id, etc.) to every log record.
- Usage:
handler.addFilter(ContextAwareFilter())
- babylon.utils.log.set_log_context(**kwargs)[source]
Set log context fields.
These fields will be automatically included in log entries when using the ContextAwareFilter.