#tracing #macro #capturing #assert #events #capture #fields

tracing-assert-macros

A macro for capturing trace logs

3 releases

0.1.4 Feb 21, 2023
0.1.3 Feb 21, 2023

#2253 in Rust patterns

MIT/Apache

9KB
114 lines

tracing-assert-macros

The tracing_capture_event_fields! macro

This macro runs a given block of code, and returns only the Field/Value tuples emitted per Event.

It's a quick way to inspect the custom data your events carry.

Example usage:

use tracing_assert_macros::tracing_capture_event_fields;
use tracing;

// Given
fn method_under_test() {
    tracing::trace!(message = "something important!");
    tracing::trace!(message = "something else important!");
}
let expected_events: Vec<Vec<(String, String) > > = vec![
    vec![("message".into(), "something important!".into())],
    vec![("message".into(), "something else important!".into())],
];

// When capturing the event field/values into the `events` variable
let events = tracing_capture_event_fields!({
    method_under_test();
});

// Then
assert_eq!(events, expected_events);

Dependencies

~1.5MB
~23K SLoC