From 5f1eb544da9f33f3402914ba5c4318032cbad0c3 Mon Sep 17 00:00:00 2001 From: vsrs Date: Wed, 27 Jan 2021 00:59:31 +0300 Subject: Apply suggestions. --- crates/rust-analyzer/src/bin/args.rs | 5 +++-- crates/rust-analyzer/src/bin/logger.rs | 23 ++++++++++++++--------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs index 100e46d2f..37d8414f4 100644 --- a/crates/rust-analyzer/src/bin/args.rs +++ b/crates/rust-analyzer/src/bin/args.rs @@ -50,7 +50,8 @@ FLAGS: -q, --quiet Set verbosity --log-file Log to the specified file instead of stderr - --no-buffering Flush log records to the file immediately + --no-log-buffering + Flush log records to the file immediately --wait-dbg Wait until a debugger is attached to. The flag is valid for debug builds only @@ -139,7 +140,7 @@ impl Args { (false, true, true) => bail!("Invalid flags: -q conflicts with -v"), }; let log_file = matches.opt_value_from_str("--log-file")?; - let no_buffering = matches.contains("--no-buffering"); + let no_buffering = matches.contains("--no-log-buffering"); let wait_dbg = matches.contains("--wait-dbg"); if matches.contains(["-h", "--help"]) { diff --git a/crates/rust-analyzer/src/bin/logger.rs b/crates/rust-analyzer/src/bin/logger.rs index 3e5cc7acf..14887c5cc 100644 --- a/crates/rust-analyzer/src/bin/logger.rs +++ b/crates/rust-analyzer/src/bin/logger.rs @@ -47,7 +47,8 @@ impl Log for Logger { if !self.filter.matches(record) { return; } - match &self.file { + + let should_flush = match &self.file { Some(w) => { let _ = writeln!( w.lock(), @@ -56,16 +57,20 @@ impl Log for Logger { record.module_path().unwrap_or_default(), record.args(), ); + self.no_buffering } - None => eprintln!( - "[{} {}] {}", - record.level(), - record.module_path().unwrap_or_default(), - record.args(), - ), - } + None => { + eprintln!( + "[{} {}] {}", + record.level(), + record.module_path().unwrap_or_default(), + record.args(), + ); + true // flush stderr unconditionally + } + }; - if self.no_buffering { + if should_flush { self.flush(); } } -- cgit v1.2.3