Struct tracing_forest::builder::LayerBuilder
source · [−]pub struct LayerBuilder<F, W, T> { /* private fields */ }
Expand description
A type for configuring TreeLayer
s.
See the module level documentation for details on using LayerBuilder
.
Implementations
impl<F, W, T> LayerBuilder<F, W, T> where
F: 'static + Formatter + Send,
W: 'static + for<'a> MakeWriter<'a> + Send,
T: Tag,
impl<F, W, T> LayerBuilder<F, W, T> where
F: 'static + Formatter + Send,
W: 'static + for<'a> MakeWriter<'a> + Send,
T: Tag,
Applies a writer that is suitable for test environments.
Configuration methods can be chained on the return value.
Examples
tracing_forest::builder()
.with_test_writer()
.blocking_layer()
.on_closure(|| {
tracing::info!("Hello, world!");
})
pub fn with_writer<W2>(self, make_writer: W2) -> LayerBuilder<F, W2, T> where
W2: for<'a> MakeWriter<'a>,
pub fn with_writer<W2>(self, make_writer: W2) -> LayerBuilder<F, W2, T> where
W2: for<'a> MakeWriter<'a>,
Applies the specified MakeWriter
.
Configuration methods can be chained on the return value.
Examples
tracing_forest::builder()
.with_writer(std::io::stderr)
.blocking_layer()
.on_closure(|| {
tracing::info!("Hello, world!");
})
Applies compact JSON formatting.
Configuration methods can be chained on the return value.
Examples
tracing_forest::builder()
.json()
.blocking_layer()
.on_closure(|| {
tracing::info!("Hello, world!");
})
{"level":"INFO","kind":{"Event":{"tag":null,"message":"Hello, world!","fields":{}}}}
Applies pretty JSON formatting.
Configuration methods can be chained on the return value.
Examples
tracing_forest::builder()
.json_pretty()
.blocking_layer()
.on_closure(|| {
tracing::info!("Hello, world!");
})
{
"level": "INFO",
"kind": {
"Event": {
"tag": null,
"message": "Hello, world!",
"fields": {}
}
}
}
Applies pretty formatting.
Configuration methods can be chained on the return value.
Examples
tracing_forest::builder()
.json_pretty()
.blocking_layer()
.on_closure(|| {
tracing::info!("Hello, world!");
})
INFO 💬 [info]: Hello, world!
Applies a custom Formatter
.
Configuration methods can be chained on the return value.
Examples
struct UselessFormatter;
impl Formatter for UselessFormatter {
fn fmt(&self, _tree: Tree, writer: &mut Vec<u8>) -> io::Result<()> {
writeln!(writer, "I am useless")
}
}
tracing_forest::builder()
.with_formatter(UselessFormatter)
.blocking_layer()
.on_closure(|| {
tracing::info!("Hello, world!");
})
I am useless
Applies a custom Tag
.
Configuration methods can be chained on the return value.
Examples
tracing_forest::declare_tags! {
use tracing_forest::Tag;
#[derive(Tag)]
pub(crate) enum MyTag {
#[tag(lvl = "info", msg = "greeting", macro = "greeting")]
Greeting,
}
}
#[test]
tracing_forest::builder()
.with_tag::<MyTag>()
.blocking_layer()
.on_closure(|| {
greeting!("Hello, world!");
})
INFO 💬 [greeting]: Hello, world!
pub fn async_layer(
self
) -> SubscriberBuilder<Layered<TreeLayer<AsyncProcessor>, Registry>, AsyncExtensions<impl Future<Output = ()>>>
pub fn async_layer(
self
) -> SubscriberBuilder<Layered<TreeLayer<AsyncProcessor>, Registry>, AsyncExtensions<impl Future<Output = ()>>>
Finalizes the layer to run with an AsyncProcessor
.
Examples
tracing_forest::builder()
.async_layer()
.on_future(async {
tracing::info!("Hello from Tokio");
})
.await
pub fn blocking_layer(
self
) -> SubscriberBuilder<Layered<TreeLayer<BlockingProcessor<F, W>>, Registry>, BlockingExtensions>
pub fn blocking_layer(
self
) -> SubscriberBuilder<Layered<TreeLayer<BlockingProcessor<F, W>>, Registry>, BlockingExtensions>
Finalizes the layer to run with a BlockingProcessor
.
Examples
tracing_forest::builder()
.blocking_layer()
.on_closure(|| {
tracing::info!("Hello from the current thread");
})
Auto Trait Implementations
impl<F, W, T> RefUnwindSafe for LayerBuilder<F, W, T> where
F: RefUnwindSafe,
W: RefUnwindSafe,
impl<F, W, T> Send for LayerBuilder<F, W, T> where
F: Send,
W: Send,
impl<F, W, T> Sync for LayerBuilder<F, W, T> where
F: Sync,
W: Sync,
impl<F, W, T> Unpin for LayerBuilder<F, W, T> where
F: Unpin,
W: Unpin,
impl<F, W, T> UnwindSafe for LayerBuilder<F, W, T> where
F: UnwindSafe,
W: UnwindSafe,
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