Skip to content

Commit 2b4d403

Browse files
bjorn3squell
authored andcommitted
Avoid interleaving logs from different processes
Previously there would be multiple write calls. One for the prefix and one or more for the log arguments. Between each write call there can be another process logging part of a log message. By instead buffering the entire log and writing it as a single write we avoid this interleaving.
1 parent e226d20 commit 2b4d403

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

src/log/simple_logger.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ where
2222
}
2323

2424
fn log(&self, record: &log::Record) {
25-
let _ = writeln!(&self.target, "{}{}", self.prefix, record.args());
25+
let s = format!("{}{}\n", self.prefix, record.args());
26+
let _ = (&self.target).write_all(s.as_bytes());
2627
}
2728

2829
fn flush(&self) {

0 commit comments

Comments
 (0)