Created
December 8, 2017 04:29
-
-
Save przygienda/bbce4cb5b7de647340d7086bf30786d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[macro_use] | |
extern crate slog; | |
extern crate slog_term; | |
extern crate slog_async; | |
extern crate slog_kvfilter; | |
extern crate slog_atomic; | |
use slog::{Logger,LevelFilter, Level}; | |
use slog_kvfilter::KVFilter; | |
use slog::Drain; | |
use slog_atomic::AtomicSwitch; | |
use std::thread::spawn; | |
fn main() { | |
// some decorating logger | |
let decorator = slog_term::TermDecorator::new().build(); | |
let drain = slog_term::CompactFormat::new(decorator).build().fuse(); | |
let drain = slog_async::Async::new(drain).build().fuse(); | |
let drain = AtomicSwitch::new(drain); | |
let set = vec![("test".to_string(), | |
vec!["1".to_string()] | |
.into_iter().collect())] | |
.into_iter().collect(); | |
let mainlog = Logger::root( | |
// all nodes show info and above if desired even if filtered | |
LevelFilter::new( | |
KVFilter::new(drain, Level::Debug, | |
set), | |
Level::Info, | |
).fuse(), o!()); | |
let mut t = vec![]; | |
// start bunch threads and log | |
for i in 0 .. 5 { | |
let log = | |
Logger::new(&mainlog,o!("thread" => format!("{}",i))); | |
t.push(spawn(move || { | |
warn!(log, "check me: {}",i); | |
})); | |
} | |
info!(&mainlog, "spawned"); | |
for th in t { | |
th.join(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment