tracing_mock::layer

Function named

Source
pub fn named(name: impl Display) -> MockLayerBuilder
Expand description

Create a MockLayerBuilder with a name already set.

This constructor is equivalent to calling MockLayerBuilder::named in the following way“ layer::mock().named(name).

For additional information and examples, see the layer module and MockLayerBuilder documentation.

§Examples

The example from MockLayerBuilder::named could be rewritten as:

use tracing_mock::{expect, layer};
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, Layer};

let (layer_1, handle_1) = layer::named("subscriber-1")
    .event(expect::event())
    .run_with_handle();

let (layer_2, handle_2) = layer::named("subscriber-2")
    .event(expect::event())
    .run_with_handle();

let _subscriber =  tracing_subscriber::registry()
    .with(
        layer_2.with_filter(tracing_subscriber::filter::filter_fn(move |_meta| true))
    )
    .set_default();
{
    let _subscriber =  tracing_subscriber::registry()
        .with(
            layer_1
                .with_filter(tracing_subscriber::filter::filter_fn(move |_meta| true))
        )
        .set_default();

    tracing::info!("a");
}

handle_1.assert_finished();
handle_2.assert_finished();