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.
Logger
s 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 Drain
s 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 Logger
s 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 Drain
s functionalities, allows custom processing logic for a
part of logging tree.
Methods
impl Logger
[src]
fn root<D, T>(d: D, values: OwnedKV<T>) -> Logger where D: 'static + Drain<Err=Never, Ok=()> + Sized + Send + Sync,
T: KV + Send + Sync + 'static
T: KV + Send + Sync + 'static
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"), ); }
fn new<T>(&self, values: OwnedKV<T>) -> Logger where T: KV + Send + Sync + 'static
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")); }
fn log(&self, record: &Record)
Log one logging Record
Use specific logging functions instead. See log!
macro
documentation.
fn list(&self) -> &OwnedKVList
Get list of key-value pairs assigned to this Logger
Trait Implementations
impl Clone for Logger
[src]
fn clone(&self) -> Logger
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more
impl Debug for Logger
[src]
impl Drain for Logger
[src]
type Ok = ()
Type returned by this drain Read more
type Err = Never
Type of potential errors that can be returned by this Drain
fn log(&self,
record: &Record,
values: &OwnedKVList)
-> Result<Self::Ok, Self::Err>
record: &Record,
values: &OwnedKVList)
-> Result<Self::Ok, Self::Err>
Handle one logging statement (Record
) Read more
fn map<F, R>(self, f: F) -> R where Self: Sized, F: FnOnce(Self) -> R
Pass Drain
through a closure, eg. to wrap into another Drain
. Read more
fn filter<F>(self, f: F) -> Filter<Self, F> where Self: Sized, F: Fn(&Record) -> bool + 'static + Send + Sync
Filter logging records passed to Drain
Read more
fn filter_level(self, level: Level) -> LevelFilter<Self> where Self: Sized
Filter logging records passed to Drain
(by level) Read more
fn map_err<F, E>(self, f: F) -> MapError<Self, E> where Self: Sized, F: 'static + Sync + Send + Fn(Self::Err) -> E
Map logging errors returned by this drain Read more
fn ignore_res(self) -> IgnoreResult<Self> where Self: Sized
Ignore results returned by this drain Read more