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 Tree
s.
Processor
s 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 Processor
s without having to
explicitly define new types.
Required Methods§
Sourcefn process(&self, tree: Tree) -> Result
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§
Sourcefn or<P: Processor>(self, processor: P) -> WithFallback<Self, P>
fn or<P: Processor>(self, processor: P) -> WithFallback<Self, P>
Sourcefn or_stdout(self) -> WithFallback<Self, Printer<Pretty, MakeStdout>>
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.
Sourcefn or_stderr(self) -> WithFallback<Self, Printer<Pretty, MakeStderr>>
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.
Sourcefn or_none(self) -> WithFallback<Self, Sink>
fn or_none(self) -> WithFallback<Self, Sink>
Returns a Processor
that first attempts processing with self
, otherwise
silently fails.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Implementors§
impl Processor for Sink
impl<F> Processor for TestCapturePrinter<F>where
F: 'static + Formatter,
impl<F> Processor for FromFn<F>
impl<F, W> Processor for Printer<F, W>where
F: 'static + Formatter,
W: 'static + for<'a> MakeWriter<'a>,
impl<P, F> Processor for WithFallback<P, F>
impl<P: Processor> Processor for InnerSender<P>
tokio
only.