Expand description

This crate allows testing code that should emit logs. It do that by capturing and recording logs for a given tracing span id.

Examples

use tracing::{error, span, Level};
use tracing_span_capture::{RecordedLogs, TracingSpanCaptureLayer};
use tracing_subscriber::layer::SubscriberExt;
use tracing_subscriber::util::SubscriberInitExt;

tracing_subscriber::fmt()
    .finish()
    .with(TracingSpanCaptureLayer)
    .init();

let span = span!(Level::INFO, "");
let record = RecordedLogs::new(&span);
{
    let _enter = span.enter();
    error!("try capture this");
}

let logs = record.into_logs();
let last_log = logs.into_iter().rev().next().unwrap();
assert_eq!(last_log.message, "try capture this");

Structs