1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use std::fmt::Display;

use tracing::Subscriber;
use tracing_subscriber::{
    prelude::__tracing_subscriber_SubscriberExt, registry::LookupSpan, Registry,
};

/// A boxed tracing Layer.
pub type BoxedLayer<S> = Box<dyn Layer<S> + Send + Sync>;

/// Initializes a new [Subscriber] based on the given layers.
pub fn init(layers: Vec<BoxedLayer<Registry>>) {
    let _ = tracing_subscriber::registry().with(layers).try_init();
}

use tracing_subscriber::{layer::Layer, util::SubscriberInitExt, EnvFilter};

pub fn stdout<S>(default_directive: impl Display) -> BoxedLayer<S>
where
    S: Subscriber,
    for<'a> S: LookupSpan<'a>,
{
    let filter = EnvFilter::builder()
        .with_default_directive(default_directive.to_string().parse().unwrap())
        .from_env_lossy()
        .add_directive("hyper::proto::h1=off".parse().unwrap());

    tracing_subscriber::fmt::layer()
        .with_ansi(true)
        .with_target(true)
        .with_filter(filter)
        .boxed()
}