Trait slog::Drain
[−]
[src]
pub trait Drain { type Ok; type Err; fn log(
&self,
record: &Record,
values: &OwnedKVList
) -> Result<Self::Ok, Self::Err>; fn map<F, R>(self, f: F) -> R
where
Self: Sized,
F: FnOnce(Self) -> R, { ... } fn filter<F>(self, f: F) -> Filter<Self, F>
where
Self: Sized,
F: FilterFn, { ... } fn filter_level(self, level: Level) -> LevelFilter<Self>
where
Self: Sized, { ... } fn map_err<F, E>(self, f: F) -> MapError<Self, E>
where
Self: Sized,
F: MapErrFn<Self::Err, E>, { ... } fn ignore_res(self) -> IgnoreResult<Self>
where
Self: Sized, { ... } fn fuse(self) -> Fuse<Self>
where
Self::Err: Debug,
Self: Sized, { ... } }
Logging drain
Drain
s typically mean destination for logs, but slog
generalizes the
term.
Drain
s are responsible for handling logging statements (Record
s) from
Logger
s associated with them: filtering, modifying, formatting
and writing the log records into given destination(s).
It's a typical pattern to parametrize Drain
s over Drain
traits to allow
composing Drain
s.
Implementing this trait allows writing custom Drain
s. Slog users should
not be afraid of implementing their own Drain
s. Any custom log handling
logic should be implemented as a Drain
.
Associated Types
type Ok
Type returned by this drain
It can be useful in some circumstances, but rarely. It will probably
default to ()
once https://github.com/rust-lang/rust/issues/29661 is
stable.
type Err
Type of potential errors that can be returned by this Drain
Required Methods
fn log(
&self,
record: &Record,
values: &OwnedKVList
) -> Result<Self::Ok, Self::Err>
&self,
record: &Record,
values: &OwnedKVList
) -> Result<Self::Ok, Self::Err>
Handle one logging statement (Record
)
Every logging Record
built from a logging statement (eg.
info!(...)
), and key-value lists of a Logger
it was executed on
will be passed to the root drain registered during Logger::root
.
Typically Drain
s:
- pass this information (or not) to the sub-logger(s) (filters)
- format and write the information the a destination (writers)
- deal with the errors returned from the sub-logger(s)
Provided Methods
fn map<F, R>(self, f: F) -> R where
Self: Sized,
F: FnOnce(Self) -> R,
Self: Sized,
F: FnOnce(Self) -> R,
Pass Drain
through a closure, eg. to wrap
into another Drain
.
#[macro_use] extern crate slog; use slog::*; fn main() { let _drain = Discard.map(Fuse); }
fn filter<F>(self, f: F) -> Filter<Self, F> where
Self: Sized,
F: FilterFn,
Self: Sized,
F: FilterFn,
Filter logging records passed to Drain
Wrap Self
in Filter
This will convert self
to a Drain that ignores
Records for which
f` returns false.
fn filter_level(self, level: Level) -> LevelFilter<Self> where
Self: Sized,
Self: Sized,
Filter logging records passed to Drain
(by level)
Wrap Self
in LevelFilter
This will convert self
to a Drain that ignores
Records of logging lever smaller than
level`.
fn map_err<F, E>(self, f: F) -> MapError<Self, E> where
Self: Sized,
F: MapErrFn<Self::Err, E>,
Self: Sized,
F: MapErrFn<Self::Err, E>,
Map logging errors returned by this drain
f
is a closure that takes Drain::Err
returned by a given
drain, and returns new error of potentially different type
fn ignore_res(self) -> IgnoreResult<Self> where
Self: Sized,
Self: Sized,
Ignore results returned by this drain
Wrap Self
in IgnoreResult
fn fuse(self) -> Fuse<Self> where
Self::Err: Debug,
Self: Sized,
Self::Err: Debug,
Self: Sized,
Make Self
panic when returning any errors
Wrap Self
in Map
Implementors
impl<D> Drain for Logger<D> where
D: SendSyncUnwindSafeDrain<Ok = (), Err = Never>,impl<D: Drain + ?Sized> Drain for Box<D>
impl<D: Drain + ?Sized> Drain for Arc<D>
impl Drain for Discard
impl<D: Drain, F> Drain for Filter<D, F> where
F: FilterFn,impl<D: Drain> Drain for LevelFilter<D>
impl<D: Drain, E> Drain for MapError<D, E>
impl<D1: Drain, D2: Drain> Drain for Duplicate<D1, D2>
impl<D: Drain> Drain for Fuse<D> where
D::Err: Debug,impl<D: Drain> Drain for IgnoreResult<D>
impl<D: Drain> Drain for Mutex<D>