Struct slog::Logger [] [src]

pub struct Logger { /* fields omitted */ }

Logging handle used to execute logging statements

Logger holds logging context (key-value pairs) and handles logging statements by delivering all logging statement information (Record) to it's Drain.

Child loggers are built from existing loggers, and inherit their existing key-value pairs, which can be supplemented with new ones.

Cloning existing loggers and creating new ones is cheap. Loggers can be freely passed around the code and between threads.

Loggers are Sync+Send - there's no need to synchronize accesses to them, as they can accept logging records from multiple threads at once. They can be sent to any thread. Because of that they require the Drain to be Sync+Sync as well. Not all Drains are Sync or Send but they can often be made so by wrapping in a Mutex and/or Arc.

Logger implements Drain trait. Any logging Record delivered to a Logger functioning as a Drain, will be delievere to it's Drain with existing key-value pairs appended to the Loggers key-value pairs. By itself it's effectively very similiar to Logger being an ancestor of Logger that originated the logging Record. However, combined with other Drains functionalities, allows custom processing logic for a part of logging tree.

Methods

impl Logger
[src]

Build a root Logger

All children and their children and so on form one logging tree sharing a common drain.

Root logger starts a new tree associated with a given Drain. Root logger drain must return no errors. See Drain::ignore_res() and Drain::fuse().

Use o! macro to build OwnedKV object.

#[macro_use]
extern crate slog;

fn main() {
    let _root = slog::Logger::root(
        slog::Discard,
        o!("key1" => "value1", "key2" => "value2"),
    );
}

Build a child logger

Child logger inherits all existing key-value pairs from it's parent.

All children, their children and so on, form one tree sharing a common drain.

Use o! macro to help build key value pairs using nicer syntax.

#[macro_use]
extern crate slog;

fn main() {
    let root = slog::Logger::root(slog::Discard,
        o!("key1" => "value1", "key2" => "value2"));
    let _log = root.new(o!("key" => "value"));
}

Log one logging Record

Use specific logging functions instead. See log! macro documentation.

Get list of key-value pairs assigned to this Logger

Trait Implementations

impl Clone for Logger
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl Debug for Logger
[src]

Formats the value using the given formatter.

impl Drain for Logger
[src]

Type returned by this drain Read more

Type of potential errors that can be returned by this Drain

Handle one logging statement (Record) Read more

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

Filter logging records passed to Drain Read more

Filter logging records passed to Drain (by level) Read more

Map logging errors returned by this drain Read more

Ignore results returned by this drain Read more