Struct tracing_forest::processor::sync::AsyncProcessor
source · [−]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.
Auto Trait Implementations
impl !RefUnwindSafe for AsyncProcessor
impl Send for AsyncProcessor
impl Sync for AsyncProcessor
impl Unpin for AsyncProcessor
impl !UnwindSafe for AsyncProcessor
Blanket Implementations
Mutably borrows from an owned value. Read more
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