From 2b2e13be636eb15445111b3c14b15f7e7e2ec028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20Ci=C4=99=C5=BCarkiewicz?= Date: Tue, 24 Apr 2018 03:02:49 -0700 Subject: [PATCH] Optimize logging (#992) `Async` 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. --- util/src/logger.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/util/src/logger.rs b/util/src/logger.rs index 1c2292cc4..c27682a2f 100644 --- a/util/src/logger.rs +++ b/util/src/logger.rs @@ -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 }; }