mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Add stderr flush
This commit is contained in:
parent
43fabfbe36
commit
98d7512e93
2 changed files with 16 additions and 8 deletions
|
@ -49,7 +49,7 @@ FLAGS:
|
||||||
-q, --quiet Set verbosity
|
-q, --quiet Set verbosity
|
||||||
|
|
||||||
--log-file <PATH> Log to the specified file instead of stderr
|
--log-file <PATH> 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:
|
ENVIRONMENTAL VARIABLES:
|
||||||
RA_LOG Set log filter in env_logger format
|
RA_LOG Set log filter in env_logger format
|
||||||
|
|
|
@ -2,7 +2,10 @@
|
||||||
//! filter syntax. Amusingly, there's no crates.io crate that can do this and
|
//! filter syntax. Amusingly, there's no crates.io crate that can do this and
|
||||||
//! only this.
|
//! 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 env_logger::filter::{Builder, Filter};
|
||||||
use log::{Log, Metadata, Record};
|
use log::{Log, Metadata, Record};
|
||||||
|
@ -53,10 +56,6 @@ impl Log for Logger {
|
||||||
record.module_path().unwrap_or_default(),
|
record.module_path().unwrap_or_default(),
|
||||||
record.args(),
|
record.args(),
|
||||||
);
|
);
|
||||||
|
|
||||||
if self.no_buffering {
|
|
||||||
w.lock().borrow_mut().flush().unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
None => eprintln!(
|
None => eprintln!(
|
||||||
"[{} {}] {}",
|
"[{} {}] {}",
|
||||||
|
@ -65,11 +64,20 @@ impl Log for Logger {
|
||||||
record.args(),
|
record.args(),
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.no_buffering {
|
||||||
|
self.flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn flush(&self) {
|
fn flush(&self) {
|
||||||
if let Some(w) = &self.file {
|
match &self.file {
|
||||||
let _ = w.lock().flush();
|
Some(w) => {
|
||||||
|
let _ = w.lock().flush();
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
let _ = io::stderr().flush();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue