Expand description
Per-test structured tracing event capture — assert on field values,
not on formatted log text.
tpt-log-tap installs a per-thread tracing subscriber for the duration of
a test, records every event (level, target, message, and structured fields)
into an in-memory buffer, and lets you assert on those fields directly. When
the returned TapGuard is dropped the subscriber is uninstalled, so tests
stay isolated even when run in parallel.
§Why field-level assertions?
Matching on rendered log strings is brittle: formatting, ANSI colour, and field ordering all change the text. Instead, capture the event and assert on the values you care about:
use tpt_log_tap::LogTap;
use tracing::Level;
let tap = LogTap::new().install();
tracing::info!(user_id = 42, action = "login", "user signed in");
tap.assert_contains(Level::INFO, "", &[("user_id", "42"), ("action", "login")]);§Isolation across parallel tests
LogTap::install uses tracing::subscriber::set_default, which scopes the
subscriber to the current thread. Each test therefore captures only its
own events, even under cargo test’s default parallelism. (For async tests
that hop threads, keep the traced work on the test’s thread — see the crate
README for details.)
Structs§
- Captured
Event - A single captured tracing event.
- LogTap
- Builder for a log tap.
- TapGuard
- RAII guard that keeps the per-thread subscriber installed and exposes the captured events for assertions.