aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/rust-analyzer/src/bin/args.rs2
-rw-r--r--crates/rust-analyzer/src/bin/logger.rs22
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:
49 -q, --quiet Set verbosity 49 -q, --quiet Set verbosity
50 50
51 --log-file <PATH> Log to the specified file instead of stderr 51 --log-file <PATH> Log to the specified file instead of stderr
52 --no-buffering Flush log records to the file immediatly 52 --no-buffering Flush log records to the file immediately
53 53
54ENVIRONMENTAL VARIABLES: 54ENVIRONMENTAL VARIABLES:
55 RA_LOG Set log filter in env_logger format 55 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 @@
2//! filter syntax. Amusingly, there's no crates.io crate that can do this and 2//! filter syntax. Amusingly, there's no crates.io crate that can do this and
3//! only this. 3//! only this.
4 4
5use std::{borrow::BorrowMut, fs::File, io::{BufWriter, Write}}; 5use std::{
6 fs::File,
7 io::{self, BufWriter, Write},
8};
6 9
7use env_logger::filter::{Builder, Filter}; 10use env_logger::filter::{Builder, Filter};
8use log::{Log, Metadata, Record}; 11use log::{Log, Metadata, Record};
@@ -53,10 +56,6 @@ impl Log for Logger {
53 record.module_path().unwrap_or_default(), 56 record.module_path().unwrap_or_default(),
54 record.args(), 57 record.args(),
55 ); 58 );
56
57 if self.no_buffering {
58 w.lock().borrow_mut().flush().unwrap();
59 }
60 } 59 }
61 None => eprintln!( 60 None => eprintln!(
62 "[{} {}] {}", 61 "[{} {}] {}",
@@ -65,11 +64,20 @@ impl Log for Logger {
65 record.args(), 64 record.args(),
66 ), 65 ),
67 } 66 }
67
68 if self.no_buffering {
69 self.flush();
70 }
68 } 71 }
69 72
70 fn flush(&self) { 73 fn flush(&self) {
71 if let Some(w) = &self.file { 74 match &self.file {
72 let _ = w.lock().flush(); 75 Some(w) => {
76 let _ = w.lock().flush();
77 }
78 None => {
79 let _ = io::stderr().flush();
80 }
73 } 81 }
74 } 82 }
75} 83}