diff --git a/Cargo.lock b/Cargo.lock index 8606b4f0d66..610ce71b635 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,6 +25,7 @@ dependencies = [ "fnv", "gl_generator", "glutin", + "lazy_static", "libc", "log", "notify", @@ -799,6 +800,12 @@ dependencies = [ "libc", ] +[[package]] +name = "itoa" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b71991ff56294aa922b450139ee08b3bfc70982c6b2c7562771375cf73542dd4" + [[package]] name = "itoa" version = "1.0.1" @@ -1419,7 +1426,7 @@ version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142" dependencies = [ - "itoa", + "itoa 1.0.1", "ryu", "serde", ] @@ -1599,14 +1606,21 @@ dependencies = [ [[package]] name = "time" -version = "0.1.43" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca8a50ef2360fbd1eeb0ecd46795a87a19024eb4b53c5dc916ca1fd95fe62438" +checksum = "41effe7cfa8af36f439fac33861b66b049edc6f9a32331e2312660529c1c24ad" dependencies = [ + "itoa 0.4.8", "libc", - "winapi 0.3.9", + "time-macros", ] +[[package]] +name = "time-macros" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25eb0ca3468fc0acc11828786797f6ef9aa1555e4a211a60d64cc8e4d1be47d6" + [[package]] name = "toml" version = "0.5.8" diff --git a/alacritty/Cargo.toml b/alacritty/Cargo.toml index 26523e1c050..0f92f3cd810 100644 --- a/alacritty/Cargo.toml +++ b/alacritty/Cargo.toml @@ -21,7 +21,7 @@ version = "0.1.0" [dependencies] clap = { version = "3.0.0", features = ["derive"] } log = { version = "0.4", features = ["std", "serde"] } -time = "0.1.40" +time = { version = "0.3.5", features = ["formatting", "local-offset", "macros"] } fnv = "1" serde = { version = "1", features = ["derive"] } serde_yaml = "0.8" @@ -35,6 +35,7 @@ libc = "0.2" unicode-width = "0.1" bitflags = "1" dirs = "3.0.1" +lazy_static = "1.4.0" [build-dependencies] gl_generator = "0.14.0" diff --git a/alacritty/src/logging.rs b/alacritty/src/logging.rs index 56ed4ab5020..ab555043f51 100644 --- a/alacritty/src/logging.rs +++ b/alacritty/src/logging.rs @@ -13,6 +13,8 @@ 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}; @@ -24,12 +26,20 @@ const ALACRITTY_LOG_ENV: &str = "ALACRITTY_LOG"; const ALLOWED_TARGETS: [&str; 4] = ["alacritty_terminal", "alacritty_config_derive", "alacritty", "crossfont"]; +lazy_static! { + static ref LOCAL_TZ: UtcOffset = UtcOffset::current_local_offset().unwrap(); +} + pub fn initialize( options: &Options, event_proxy: EventLoopProxy, ) -> Result, log::SetLoggerError> { log::set_max_level(options.log_level()); + // LOCAL_TZ must be initialized before spawning any threads, otherwise the call will fail due + // to unsoundness of get/setenv in multi-threaded applications. + let _ = *LOCAL_TZ; + let logger = Logger::new(event_proxy); let path = logger.file_path(); log::set_boxed_logger(Box::new(logger))?; @@ -128,7 +138,12 @@ impl log::Log for Logger { } fn create_log_message(record: &log::Record<'_>, target: &str) -> String { - let now = time::strftime("%F %T.%f", &time::now()).unwrap(); + let now = OffsetDateTime::now_utc() + .to_offset(*LOCAL_TZ) + .format(format_description!( + "[year]-[month]-[day] [hour repr:24]:[minute]:[second].[subsecond digits:9]Z" + )) + .unwrap(); let mut message = format!("[{}] [{:<5}] [{}] ", now, record.level(), target); // Alignment for the lines after the first new line character in the payload. We don't deal diff --git a/alacritty/src/main.rs b/alacritty/src/main.rs index 6a86fcb144c..d5b298862ae 100644 --- a/alacritty/src/main.rs +++ b/alacritty/src/main.rs @@ -24,6 +24,9 @@ use log::info; #[cfg(windows)] use winapi::um::wincon::{AttachConsole, FreeConsole, ATTACH_PARENT_PROCESS}; +#[macro_use] +extern crate lazy_static; + use alacritty_terminal::tty; mod cli;