mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-28 20:16:58 +03:00
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 <mahdif1380@outlook.com>
This commit is contained in:
@@ -48,31 +48,31 @@ fn log(&self, record: &Record) {
|
||||
return;
|
||||
}
|
||||
|
||||
let should_flush = match &self.file {
|
||||
match &self.file {
|
||||
Some(w) => {
|
||||
let mut writer = w.lock();
|
||||
let _ = writeln!(
|
||||
w.lock(),
|
||||
writer,
|
||||
"[{} {}] {}",
|
||||
record.level(),
|
||||
record.module_path().unwrap_or_default(),
|
||||
record.args(),
|
||||
);
|
||||
self.no_buffering
|
||||
|
||||
if self.no_buffering {
|
||||
let _ = writer.flush();
|
||||
}
|
||||
}
|
||||
None => {
|
||||
eprintln!(
|
||||
"[{} {}] {}",
|
||||
let message = format!(
|
||||
"[{} {}] {}\n",
|
||||
record.level(),
|
||||
record.module_path().unwrap_or_default(),
|
||||
record.args(),
|
||||
);
|
||||
true // flush stderr unconditionally
|
||||
eprint!("{}", message);
|
||||
}
|
||||
};
|
||||
|
||||
if should_flush {
|
||||
self.flush();
|
||||
}
|
||||
}
|
||||
|
||||
fn flush(&self) {
|
||||
|
||||
Reference in New Issue
Block a user