From 799ec79f18e627f8d14d3520f2e1abff265c1abe Mon Sep 17 00:00:00 2001 From: mahdi-frms Date: Mon, 5 Jul 2021 19:46:09 +0430 Subject: [PATCH 1/2] make the logs line buffered --- crates/rust-analyzer/src/bin/logger.rs | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/crates/rust-analyzer/src/bin/logger.rs b/crates/rust-analyzer/src/bin/logger.rs index 14887c5ccf..35b3a9d696 100644 --- a/crates/rust-analyzer/src/bin/logger.rs +++ b/crates/rust-analyzer/src/bin/logger.rs @@ -48,7 +48,7 @@ impl Log for Logger { return; } - let should_flush = match &self.file { + match &self.file { Some(w) => { let _ = writeln!( w.lock(), @@ -57,22 +57,21 @@ impl Log for Logger { record.module_path().unwrap_or_default(), record.args(), ); - self.no_buffering + + if self.no_buffering { + self.flush(); + } } None => { - eprintln!( - "[{} {}] {}", + let message = format!( + "[{} {}] {}\n", record.level(), record.module_path().unwrap_or_default(), record.args(), ); - true // flush stderr unconditionally + eprint!("{}", message); } }; - - if should_flush { - self.flush(); - } } fn flush(&self) { From 60e304c7b6f56b389c9f3ca723f206d9c3f3e735 Mon Sep 17 00:00:00 2001 From: mahdi-frms Date: Mon, 5 Jul 2021 20:52:34 +0430 Subject: [PATCH 2/2] refactor logger flushing --- crates/rust-analyzer/src/bin/logger.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/rust-analyzer/src/bin/logger.rs b/crates/rust-analyzer/src/bin/logger.rs index 35b3a9d696..f8f57b2aa7 100644 --- a/crates/rust-analyzer/src/bin/logger.rs +++ b/crates/rust-analyzer/src/bin/logger.rs @@ -50,8 +50,9 @@ impl Log for Logger { match &self.file { Some(w) => { + let mut writer = w.lock(); let _ = writeln!( - w.lock(), + writer, "[{} {}] {}", record.level(), record.module_path().unwrap_or_default(), @@ -59,7 +60,7 @@ impl Log for Logger { ); if self.no_buffering { - self.flush(); + let _ = writer.flush(); } } None => {