From 768f9e22854231a95b96fea58c9e1a56bbc5ec89 Mon Sep 17 00:00:00 2001 From: Kirill Chibisov Date: Thu, 19 Nov 2020 18:45:13 +0300 Subject: [PATCH] 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. --- alacritty/src/logging.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/alacritty/src/logging.rs b/alacritty/src/logging.rs index e2636b81..a7ca3ac7 100644 --- a/alacritty/src/logging.rs +++ b/alacritty/src/logging.rs @@ -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) {}