From 98d7512e93ea66f1a259623f9f534bee4a922a81 Mon Sep 17 00:00:00 2001 From: vsrs Date: Sun, 24 Jan 2021 17:41:02 +0300 Subject: Add stderr flush --- crates/rust-analyzer/src/bin/args.rs | 2 +- crates/rust-analyzer/src/bin/logger.rs | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/crates/rust-analyzer/src/bin/args.rs b/crates/rust-analyzer/src/bin/args.rs index 4ec755769..32d7836ff 100644 --- a/crates/rust-analyzer/src/bin/args.rs +++ b/crates/rust-analyzer/src/bin/args.rs @@ -49,7 +49,7 @@ FLAGS: -q, --quiet Set verbosity --log-file Log to the specified file instead of stderr - --no-buffering Flush log records to the file immediatly + --no-buffering Flush log records to the file immediately ENVIRONMENTAL VARIABLES: RA_LOG Set log filter in env_logger format diff --git a/crates/rust-analyzer/src/bin/logger.rs b/crates/rust-analyzer/src/bin/logger.rs index 4ea4ffafb..3e5cc7acf 100644 --- a/crates/rust-analyzer/src/bin/logger.rs +++ b/crates/rust-analyzer/src/bin/logger.rs @@ -2,7 +2,10 @@ //! filter syntax. Amusingly, there's no crates.io crate that can do this and //! only this. -use std::{borrow::BorrowMut, fs::File, io::{BufWriter, Write}}; +use std::{ + fs::File, + io::{self, BufWriter, Write}, +}; use env_logger::filter::{Builder, Filter}; use log::{Log, Metadata, Record}; @@ -53,10 +56,6 @@ impl Log for Logger { record.module_path().unwrap_or_default(), record.args(), ); - - if self.no_buffering { - w.lock().borrow_mut().flush().unwrap(); - } } None => eprintln!( "[{} {}] {}", @@ -65,11 +64,20 @@ impl Log for Logger { record.args(), ), } + + if self.no_buffering { + self.flush(); + } } fn flush(&self) { - if let Some(w) = &self.file { - let _ = w.lock().flush(); + match &self.file { + Some(w) => { + let _ = w.lock().flush(); + } + None => { + let _ = io::stderr().flush(); + } } } } -- cgit v1.2.3