pub trait Processor: 'static + Sized {
    // Required method
    fn process(&self, tree: Tree) -> Result;

    // Provided methods
    fn or<P: Processor>(self, processor: P) -> WithFallback<Self, P> { ... }
    fn or_stdout(self) -> WithFallback<Self, Printer<Pretty, MakeStdout>> { ... }
    fn or_stderr(self) -> WithFallback<Self, Printer<Pretty, MakeStderr>> { ... }
    fn or_none(self) -> WithFallback<Self, Sink> { ... }
}
Expand description

A trait for processing completed Trees.

Processors are responsible for both formatting and writing logs to their intended destinations. This is typically implemented using Formatter, MakeWriter, and io::Write.

While this trait may be implemented on downstream types, from_fn provides a convenient interface for creating Processors without having to explicitly define new types.

Required Methods§

source

fn process(&self, tree: Tree) -> Result

Process a Tree. This can mean many things, such as writing to stdout or a file, sending over a network, storing in memory, ignoring, or anything else.

Errors

If the Tree cannot be processed, then it is returned along with a Box<dyn Error + Send + Sync>. If the processor is configured with a fallback processor from Processor::or, then the Tree is deferred to that processor.

Provided Methods§

source

fn or<P: Processor>(self, processor: P) -> WithFallback<Self, P>

Returns a Processor that first attempts processing with self, and resorts to processing with fallback on failure.

Note that or_stdout, or_stderr, and or_none can be used as shortcuts for pretty printing or dropping the Tree entirely.

source

fn or_stdout(self) -> WithFallback<Self, Printer<Pretty, MakeStdout>>

Returns a Processor that first attempts processing with self, and resorts to pretty-printing to stdout on failure.

source

fn or_stderr(self) -> WithFallback<Self, Printer<Pretty, MakeStderr>>

Returns a Processor that first attempts processing with self, and resorts to pretty-printing to stderr on failure.

source

fn or_none(self) -> WithFallback<Self, Sink>

Returns a Processor that first attempts processing with self, otherwise silently fails.

Implementations on Foreign Types§

source§

impl<P: Processor> Processor for Box<P>

source§

fn process(&self, tree: Tree) -> Result

source§

impl<P: Processor> Processor for Arc<P>

source§

fn process(&self, tree: Tree) -> Result

Implementors§

source§

impl Processor for Sink

source§

impl<F> Processor for TestCapturePrinter<F>where F: 'static + Formatter,

source§

impl<F> Processor for FromFn<F>where F: 'static + Fn(Tree) -> Result,

source§

impl<F, W> Processor for Printer<F, W>where F: 'static + Formatter, W: 'static + for<'a> MakeWriter<'a>,

source§

impl<P, F> Processor for WithFallback<P, F>where P: Processor, F: Processor,

source§

impl<P: Processor> Processor for InnerSender<P>