slog-scope 0.1.0

Logging scopes for slog-rs
Documentation

Logging scopes for slog-rs

Logging scopes are convinience functionality for slog-rs that free user from manually passing Logger objects around

Note: Part of a slog logging philosophy is ability to freelly express logging contexts acording to logical structure, rather than code structure. By using logging scopes logging context is tied to code flow again, which is less expressive.

[macro_use]
extern crate slog;
extern crate slog_scope;
extern crate slog_term;

use slog::DrainExt;

fn foo() {
    info!(slog_scope::logger(), "foo");
}

fn main() {
    let log = slog::Logger::root(slog_term::streamer().stderr().build().fuse(), o!("version" => "0.5"));

    slog_scope::set_global_logger(log);
    slog_scope::scope(slog_scope::logger().new(o!("scope" => "1")),
        || foo()
    );
}