From e38f51c6bd73999e4e36110ca21cdb473de00bd5 Mon Sep 17 00:00:00 2001 From: Christian Duerr Date: Thu, 13 Jan 2022 06:36:22 +0100 Subject: Remove time dependency In 7398e9f a regression was introduced which causes Alacritty to crash on startup since wayland has a keyboard repeat rate thread started before our logger is initialized. Since the latest version of time was rather inconvenient to use anyway and there is no nice solution for this issue other than downgrading the `time` version again, the time since startup is now logged instead of the local time. This should still provide all the relevant information, while getting rid of an unnecessary dependency. While it would be possible to also print the delta between log messages, this can be trivially computed so it has been omitted to skip adding another `Mutex` to the `Logger` struct. --- alacritty/src/logging.rs | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) (limited to 'alacritty/src') diff --git a/alacritty/src/logging.rs b/alacritty/src/logging.rs index 0ed37220..3ac40e4b 100644 --- a/alacritty/src/logging.rs +++ b/alacritty/src/logging.rs @@ -9,12 +9,11 @@ use std::io::{self, LineWriter, Stdout, Write}; use std::path::PathBuf; use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::{Arc, Mutex}; +use std::time::Instant; use std::{env, process}; use glutin::event_loop::EventLoopProxy; use log::{self, Level, LevelFilter}; -use time::macros::format_description; -use time::{OffsetDateTime, UtcOffset}; use crate::cli::Options; use crate::event::{Event, EventType}; @@ -43,7 +42,7 @@ pub struct Logger { logfile: Mutex, stdout: Mutex>, event_proxy: Mutex>, - tz_offset: UtcOffset, + start: Instant, } impl Logger { @@ -51,12 +50,7 @@ impl Logger { let logfile = Mutex::new(OnDemandLogFile::new()); let stdout = Mutex::new(LineWriter::new(io::stdout())); - Logger { - logfile, - stdout, - event_proxy: Mutex::new(event_proxy), - tz_offset: UtcOffset::current_local_offset().expect("local timezone offset"), - } + Logger { logfile, stdout, event_proxy: Mutex::new(event_proxy), start: Instant::now() } } fn file_path(&self) -> Option { @@ -116,7 +110,7 @@ impl log::Log for Logger { } // Create log message for the given `record` and `target`. - let message = create_log_message(record, target, self.tz_offset); + let message = create_log_message(record, target, self.start); if let Ok(mut logfile) = self.logfile.lock() { // Write to logfile. @@ -135,12 +129,11 @@ impl log::Log for Logger { fn flush(&self) {} } -fn create_log_message(record: &log::Record<'_>, target: &str, tz_offset: UtcOffset) -> String { - let time_format = format_description!( - "[year]-[month]-[day] [hour repr:24]:[minute]:[second].[subsecond digits:9]" - ); - let now = OffsetDateTime::now_utc().to_offset(tz_offset).format(time_format).unwrap(); - let mut message = format!("[{}] [{:<5}] [{}] ", now, record.level(), target); +fn create_log_message(record: &log::Record<'_>, target: &str, start: Instant) -> String { + let runtime = start.elapsed(); + let secs = runtime.as_secs(); + let nanos = runtime.subsec_nanos(); + let mut message = format!("[{}.{:0>9}s] [{:<5}] [{}] ", secs, nanos, record.level(), target); // Alignment for the lines after the first new line character in the payload. We don't deal // with fullwidth/unicode chars here, so just `message.len()` is sufficient. -- cgit