Skip to content

Commit 91bfa4b

Browse files
bors[bot]mahdifrmz
andauthored
Merge #9496
9496: fix: make the logs line buffered r=lnicola a=mahdi-frms fixes #9432 Not quite sure if that's what you want, but storing the log message in buffers eliminated the tiny write syscalls for me. I just changed the Logger struct. Co-authored-by: mahdi-frms <[email protected]>
2 parents 8b8eac5 + 60e304c commit 91bfa4b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

crates/rust-analyzer/src/bin/logger.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -48,31 +48,31 @@ impl Log for Logger {
4848
return;
4949
}
5050

51-
let should_flush = match &self.file {
51+
match &self.file {
5252
Some(w) => {
53+
let mut writer = w.lock();
5354
let _ = writeln!(
54-
w.lock(),
55+
writer,
5556
"[{} {}] {}",
5657
record.level(),
5758
record.module_path().unwrap_or_default(),
5859
record.args(),
5960
);
60-
self.no_buffering
61+
62+
if self.no_buffering {
63+
let _ = writer.flush();
64+
}
6165
}
6266
None => {
63-
eprintln!(
64-
"[{} {}] {}",
67+
let message = format!(
68+
"[{} {}] {}\n",
6569
record.level(),
6670
record.module_path().unwrap_or_default(),
6771
record.args(),
6872
);
69-
true // flush stderr unconditionally
73+
eprint!("{}", message);
7074
}
7175
};
72-
73-
if should_flush {
74-
self.flush();
75-
}
7676
}
7777

7878
fn flush(&self) {

0 commit comments

Comments
 (0)