Optimize logging (#992)

`Async<Discard>` means "drain that will send each logging
record to an async thread, that will discard it". This means
logging record is sent to another thread for no reason.
This commit is contained in:
Dawid Ciężarkiewicz 2018-04-24 03:02:49 -07:00 committed by Yeastplume
parent 5bc9e29974
commit 2b2e13be63

View file

@ -64,9 +64,8 @@ lazy_static! {
terminal_drain = slog_async::Async::new(Discard{}).build().fuse();
}
//File drain
let mut file_drain_final = slog_async::Async::new(Discard{}).build().fuse();
if config.log_to_file && was_init {
//File drain
let file = OpenOptions::new()
.create(true)
.write(true)
@ -78,14 +77,14 @@ lazy_static! {
let file_decorator = slog_term::PlainDecorator::new(file);
let file_drain = slog_term::FullFormat::new(file_decorator).build().fuse();
let file_drain = LevelFilter::new(file_drain, slog_level_file).fuse();
file_drain_final = slog_async::Async::new(file_drain).build().fuse();
let file_drain_final = slog_async::Async::new(file_drain).build().fuse();
let composite_drain = Duplicate::new(terminal_drain, file_drain_final).fuse();
Logger::root(composite_drain, o!())
} else {
Logger::root(terminal_drain, o!())
}
//Compose file and terminal drains
let composite_drain = Duplicate::new(terminal_drain, file_drain_final).fuse();
let log = Logger::root(composite_drain, o!());
log
};
}