#[macro_use]
extern crate slog;
use std::cell::RefCell;
use std::thread;
use slog::Logger;
thread_local!(static TL_LOG: RefCell<Logger> = RefCell::new(
Logger::root(slog::discard(), o!("logger" => "unititalized"))
));
fn foo() {
TL_LOG.with(|log| {
info!(log.borrow(), "foo called");
});
}
fn main() {
let root = slog::Logger::root(
slog::discard(),
o!("version" => "0.0.1", "build-id" => "8dfljdf"),
);
TL_LOG.with(|log| {
*log.borrow_mut() = root.new(o!("thread-id" => "main"));
});
let mut join = vec![];
for i in 0..4 {
join.push(thread::spawn({
let root = root.clone();
move || {
TL_LOG.with(|log| {
*log.borrow_mut() = root.new(o!("thread-id" => format!("thread{}", i)));
});
foo();
}
}));
}
foo();
for join in join {
join.join().unwrap();
}
}