pub trait Formatter {
type Error: Error + Send + Sync;
// Required method
fn fmt(&self, tree: &Tree) -> Result<String, Self::Error>;
}Expand description
Format a Tree into a String.
§Examples
This trait implements all Fn(&Tree) -> Result<String, E> types, where E: Error + Send + Sync.
If the serde feature is enabled, functions like serde_json::to_string_pretty
can be used wherever a Formatter is required.
tracing_forest::worker_task()
.map_receiver(|receiver| {
receiver.formatter(serde_json::to_string_pretty)
})
.build()
.on(async {
info!("write this as json");
})
.awaitProduces the following result:
{
"Event": {
"uuid": "00000000-0000-0000-0000-000000000000",
"timestamp": "2022-03-24T16:08:17.761149+00:00",
"level": "INFO",
"message": "write this as json",
"tag": "info",
"fields": {}
}
}