slog-vmodule

Crates.ioslog-vmodule
lib.rsslog-vmodule
version0.1.0
sourcesrc
created_at2019-08-21 10:15:20.954574
updated_at2019-08-21 10:15:20.954574
descriptionModule based level filter Drain for slog-rs
homepagehttps://github.com/codeb2cc/slog-vmodule
repositoryhttps://github.com/codeb2cc/slog-vmodule
max_upload_size
id158618
size13,190
Codeb Fan (codeb2cc)

documentation

https://docs.rs/slog-vmodule

README

Build Status codecov

slog-vmodule - Module based level filter Drain for slog-rs

Features

Filter Drain provides fine-grained control over logging at the module(logger name) level. Examples: With flag foo=debug,bar=error and default level INFO, a debug log will only be drain if it's from foo but not from bar. And logs from bar must have a at least ERROR level to pass. Other logs without module name continue to adopt the default INFO setting.

Usage

    // ... 

    let vmodule: HashMap<String, Level> = [
        ("foo".to_owned(), Level::Debug),
        ("bar".to_owned(), Level::Error),
    ]
    .iter()
    .cloned()
    .collect();
    // Or parse from flag string
    //let vmodule: HashMap<String, Level> = ModLevelFilterConfig("foo=debug,bar=error".to_string()).into();

    // Module name key("module" here) is configurable. Use whatever you like.
    let filter =
        ModLevelFilter::new(drain, "module".to_owned(), Level::Warning, vmodule).fuse();

    // Logger for different modules
    let root_log = Logger::root(filter.fuse(), o!());
    let foo_log = root_log.new(o!("module" => "foo"));
    let bar_log = root_log.new(o!("module" => "bar"));

    info!(root_log, "Not Pass");
    info!(foo_log, "Pass");
    info!(bar_log, "Not Pass");

    // ...
Commit count: 5

cargo fmt