Trait slog::Drain [] [src]

pub trait Drain {
    type Ok;
    type Err;
    fn log(
        record: &Record,
        values: &OwnedKVList
    ) -> Result<Self::Ok, Self::Err>; fn map<F, R>(self, f: F) -> R
        Self: Sized,
        F: FnOnce(Self) -> R
, { ... } fn filter<F>(self, f: F) -> Filter<Self, F>
        Self: Sized,
        F: FilterFn
, { ... } fn filter_level(self, level: Level) -> LevelFilter<Self>
        Self: Sized
, { ... } fn map_err<F, E>(self, f: F) -> MapError<Self, E>
        Self: Sized,
        F: MapErrFn<Self::Err, E>
, { ... } fn ignore_res(self) -> IgnoreResult<Self>
        Self: Sized
, { ... } fn fuse(self) -> Fuse<Self>
        Self::Err: Debug,
        Self: Sized
, { ... } }

Logging drain

Drains typically mean destination for logs, but slog generalizes the term.

Drains are responsible for handling logging statements (Records) from Loggers associated with them: filtering, modifying, formatting and writing the log records into given destination(s).

It's a typical pattern to parametrize Drains over Drain traits to allow composing Drains.

Implementing this trait allows writing custom Drains. Slog users should not be afraid of implementing their own Drains. Any custom log handling logic should be implemented as a Drain.

Associated Types

Type returned by this drain

It can be useful in some circumstances, but rarely. It will probably default to () once is stable.

Type of potential errors that can be returned by this Drain

Required Methods

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 Drains:

  • 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

Pass Drain through a closure, eg. to wrap into another Drain.

extern crate slog;
use slog::*;

fn main() {
    let _drain =;

Filter logging records passed to Drain

Wrap Self in Filter

This will convert self to a Drain that ignoresRecords for whichf` returns false.

Filter logging records passed to Drain (by level)

Wrap Self in LevelFilter

This will convert self to a Drain that ignoresRecords of logging lever smaller thanlevel`.

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

Ignore results returned by this drain

Wrap Self in IgnoreResult

Make Self panic when returning any errors

Wrap Self in Map