Crates.io | slog-vmodule |
lib.rs | slog-vmodule |
version | 0.1.0 |
source | src |
created_at | 2019-08-21 10:15:20.954574 |
updated_at | 2019-08-21 10:15:20.954574 |
description | Module based level filter Drain for slog-rs |
homepage | https://github.com/codeb2cc/slog-vmodule |
repository | https://github.com/codeb2cc/slog-vmodule |
max_upload_size | |
id | 158618 |
size | 13,190 |
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.
// ...
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");
// ...