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");
    })
    .await

Produces 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": {}
  }
}

Required Associated Types§

source

type Error: Error + Send + Sync

The error type if the Tree cannot be stringified.

Required Methods§

source

fn fmt(&self, tree: &Tree) -> Result<String, Self::Error>

Stringifies the Tree, or returns an error.

Errors

If the Tree cannot be formatted to a string, an error is returned.

Implementors§

source§

impl Formatter for Pretty

§

type Error = Error

source§

impl<F, E> Formatter for Fwhere F: Fn(&Tree) -> Result<String, E>, E: Error + Send + Sync,

§

type Error = E