pub struct AsyncProcessor { /* private fields */ }
Expand description

A Processor that sends logs to another tokio task for processing.

This type is usually created and used by the LayerBuilder type.

Implementations

Create a new AsyncProcessor and Future for processing, returning the processor and the future.

Examples

In a function that runs indefinitely, where the writing thread doesn’t need to explicitly be awaited:

#[tokio::main(flavor = "current_thread")]
async fn main() {
    let (processor, fut) = AsyncProcessor::spawn(Pretty::new(), std::io::stdout);
    tokio::spawn(fut);
    tracing::subscriber::set_global_default({
        processor
            .into_layer()
            .into_subscriber()
    }).unwrap();
     
    start_server().await;
}

In a function that terminates, where the writing thread needs to be explicitly awaited before going out of scope:

#[tokio::test]
async fn my_short_test() {
    let (processor, fut) = AsyncProcessor::spawn(Pretty::new(), std::io::stdout);
    let handle = tokio::spawn(fut);
     
    let guard = tracing::subscriber::set_default({
        processor
            .into_layer()
            .into_subscriber()
    });

    tracing::info!(satisfied = true, "it works!");
     
    // drop subscriber to close all senders
    drop(guard);
    handle.await.unwrap();
}

Trait Implementations

Performs the conversion.

Processes the Tree of logs. Implementors of this trait are free to define what this means, such as: Read more

Converts the Processor into a TreeLayer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more