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:
bors[bot] 2021-07-05 17:11:09 +00:00 committed by GitHub
commit 91bfa4b154
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -48,31 +48,31 @@ impl Log for Logger {
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) {