Fix stdout log message order

This patch makes sure that the message for the creation of a log file is
always the first entry, before any other log file messages.

Since we initialize our log file dynamically, the message is printed as
soon as something is written to it. By making sure that we always write
to a file first and then try stdout, we can ensure that the log file is
always initialized before ever writing log messages to stdout.
This commit is contained in:
Kirill Chibisov 2020-11-19 18:45:13 +03:00 committed by GitHub
parent c1f0e83cbb
commit 768f9e2285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 5 deletions

View File

@ -110,11 +110,6 @@ impl log::Log for Logger {
let now = time::strftime("%F %T.%f", &time::now()).unwrap();
let msg = format!("[{}] [{:<5}] [{}] {}\n", now, record.level(), target, record.args());
// Write to stdout.
if let Ok(mut stdout) = self.stdout.lock() {
let _ = stdout.write_all(msg.as_ref());
}
if let Ok(mut logfile) = self.logfile.lock() {
// Write to logfile.
let _ = logfile.write_all(msg.as_ref());
@ -124,6 +119,11 @@ impl log::Log for Logger {
self.message_bar_log(record, &logfile.path.to_string_lossy());
}
}
// Write to stdout.
if let Ok(mut stdout) = self.stdout.lock() {
let _ = stdout.write_all(msg.as_ref());
}
}
fn flush(&self) {}