Skip to main content

Module fmt

Module fmt 

Source
Expand description

tracing_subscriber::fmt integration that uses simulation time as the timestamp prefix.

By default, tracing_subscriber::fmt::layer() prints wall-clock time — useless in simulation, where logical time skips idle periods and seconds of simulated activity may take milliseconds of wall time. SimTime prints “current sim time in milliseconds” reported by a Clock instead.

Clock is the narrow Send + Sync source of sim time the formatter needs. super::SimulationLayerHandle implements it; users can also implement it for testing stubs or alternate time sources.

§Usage

use moonpool_sim::{SimTime, SimulationLayer};
use tracing_subscriber::layer::SubscriberExt;

let layer = SimulationLayer::new();
let handle = layer.handle();

// Important: register `SimulationLayer` BEFORE the fmt layer so its
// on_event runs first and updates the layer's sim time before fmt
// formats the event.
let subscriber = tracing_subscriber::registry()
    .with(layer)
    .with(
        tracing_subscriber::fmt::layer()
            .with_timer(SimTime::new(handle.clone())),
    );

let _guard = tracing::subscriber::set_default(subscriber);

Output looks like:

sim+    1.234s  INFO moonpool::sim: key="delivery.at_most_once" payload=Replied { seq_id: 7 }

Structs§

SimTime
FormatTime implementation that writes simulation time reported by a Clock instead of wall-clock time.

Traits§

Clock
Narrow Send + Sync source of simulation time, suitable for plugging into the SimTime formatter.