Tracer API

This module contains the centralized logging utility for the simulation engine.

class ml.tracer.LogRecord(timestamp, thread_name, component_id, event, details, level)

Bases: tuple

component_id

Alias for field number 2

details

Alias for field number 4

event

Alias for field number 3

level

Alias for field number 5

thread_name

Alias for field number 1

timestamp

Alias for field number 0

class ml.tracer.Tracer[source]

Bases: object

A thread-safe, centralized logging utility for the simulation engine.

It buffers log records and periodically flushes them to the console and/or a file in a formatted, column-aligned manner.

classmethod log(level: LogLevel, component_id: str, event: str, details: Dict[str, Any] | None = None)[source]

Adds a log record to the buffer.

This method is thread-safe.

Parameters:
  • level – The severity level of the log.

  • component_id – The identifier of the component logging the event.

  • event – The name of the event being logged.

  • details – An optional dictionary of structured data.

classmethod start(level: LogLevel, flush_interval_seconds: float, output_file: str | None, log_to_console: bool = True, error_file: str | None = 'errors.log')[source]

Initializes and starts the tracer thread.

Parameters:
  • level – The minimum log level to record.

  • flush_interval_seconds – How often to flush logs.

  • output_file – An optional file path to write logs to.

  • log_to_console – If True, logs will also be printed to the console.

  • error_file – An optional file path to write detailed exception tracebacks to.

classmethod stop()[source]

Stops the tracer thread and performs a final flush of all logs.