diff options
author | Christian Duerr <contact@christianduerr.com> | 2022-01-13 06:36:22 +0100 |
---|---|---|
committer | Christian Duerr <contact@christianduerr.com> | 2022-01-13 15:08:26 +0100 |
commit | 97705e0746133dee39ad998447defa4f0ddaf09b (patch) | |
tree | 6781b030f0b671e8440bde61ab034051ea60fdbc | |
parent | a4db1a1f5144cab5f94edcacf7602930438e628e (diff) | |
download | alacritty-97705e0746133dee39ad998447defa4f0ddaf09b.tar.gz alacritty-97705e0746133dee39ad998447defa4f0ddaf09b.zip |
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.
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | Cargo.lock | 108 | ||||
-rw-r--r-- | alacritty/Cargo.toml | 1 | ||||
-rw-r--r-- | alacritty/src/logging.rs | 25 |
4 files changed, 51 insertions, 84 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 3de2a444..ea84d73c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -28,6 +28,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - Commands spawn from the current directory of the foreground shell in Unix-like systems - Remove trailing newline from strings taken from hints or simple/semantic selections - Builtin font is now used for box drawing characters from `U+2500` to `U+259f` +- Logs now print the time since startup instead of the local time ### Fixed @@ -35,7 +35,6 @@ dependencies = [ "serde_json", "serde_yaml", "structopt", - "time", "unicode-width", "wayland-client", "winapi 0.3.9", @@ -134,9 +133,9 @@ checksum = "0d8c1fef690941d3e7788d328517591fecc684c084084702d6ff1641e993699a" [[package]] name = "bumpalo" -version = "3.8.0" +version = "3.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f1e260c3a9040a7c19a12468758f4c16f31a81a1fe087482be9570ec864bb6c" +checksum = "a4a45a46ab1f2412e53d3a0ade76ffad2025804294569aae387231a0cd6e0899" [[package]] name = "calloop" @@ -202,9 +201,9 @@ dependencies = [ [[package]] name = "cmake" -version = "0.1.46" +version = "0.1.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7b858541263efe664aead4a5209a4ae5c5d2811167d4ed4ee0944503f8d2089" +checksum = "e8ad8cef104ac57b68b89df3208164d228503abbdce70f6880ffa3d970e7443a" dependencies = [ "cc", ] @@ -420,17 +419,6 @@ dependencies = [ ] [[package]] -name = "derivative" -version = "2.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fcc3dd5e9e9c0b295d6e1e4d811fb6f157d5ffd784b8d202fc62eac8035a770b" -dependencies = [ - "proc-macro2", - "quote", - "syn", -] - -[[package]] name = "dirs" version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -749,9 +737,9 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "indexmap" -version = "1.7.0" +version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc633605454125dec4b66843673f01c7df2b89479b32e0ed634e43a91cff62a5" +checksum = "282a6247722caba404c065016bbfa522806e51714c34f5dfc3e4a3a46fcb4223" dependencies = [ "autocfg", "hashbrown", @@ -800,12 +788,6 @@ dependencies = [ [[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" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1aab8fc367588b89dcee83ab0fd66b72b50b72fa1904d7095045ace2b0c81c35" @@ -861,9 +843,9 @@ checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" [[package]] name = "libc" -version = "0.2.109" +version = "0.2.112" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f98a04dce437184842841303488f70d0188c5f51437d2a834dc097eafa909a01" +checksum = "1b03d17f364a3a042d5e5d46b053bbbf82c92c9430c592dd4c064dc6ee997125" [[package]] name = "libloading" @@ -1147,19 +1129,18 @@ dependencies = [ [[package]] name = "num_enum" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f9bd055fb730c4f8f4f57d45d35cd6b3f0980535b056dc7ff119cee6a66ed6f" +checksum = "720d3ea1055e4e4574c0c0b0f8c3fd4f24c4cdaf465948206dea090b57b526ad" dependencies = [ - "derivative", "num_enum_derive", ] [[package]] name = "num_enum_derive" -version = "0.5.4" +version = "0.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "486ea01961c4a818096de679a8b740b26d9033146ac5291b1c98557658f8cdd9" +checksum = "0d992b768490d7fe0d8586d9b5745f6c49f557da6d81dc982b1d167ad4edbb21" dependencies = [ "proc-macro-crate", "proc-macro2", @@ -1198,9 +1179,9 @@ dependencies = [ [[package]] name = "once_cell" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" [[package]] name = "osmesa-sys" @@ -1295,18 +1276,27 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.33" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb37d2df5df740e582f28f8560cf425f52bb267d872fe58358eadb554909f07a" +checksum = "c7342d5883fbccae1cc37a2353b09c87c9b0f3afd73f5fb9bba687a1f733b029" dependencies = [ "unicode-xid", ] [[package]] +name = "quick-xml" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8533f14c8382aaad0d592c812ac3b826162128b65662331e1127b45c3d18536b" +dependencies = [ + "memchr", +] + +[[package]] name = "quote" -version = "1.0.10" +version = "1.0.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38bc8cc6a5f2e3655e0899c1b848643b2562f853f114bfec7be120678e3ace05" +checksum = "47aa80447ce4daf1717500037052af176af5d38cc3e571d9ec1c7353fc10c87d" dependencies = [ "proc-macro2", ] @@ -1356,9 +1346,9 @@ checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" [[package]] name = "ryu" -version = "1.0.7" +version = "1.0.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "254df5081ce98661a883445175e52efe99d1cb2a5552891d965d2f5d0cad1c16" +checksum = "73b4b750c782965c211b42f022f59af1fbceabdd026623714f104152f1ec149f" [[package]] name = "same-file" @@ -1407,7 +1397,7 @@ version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142" dependencies = [ - "itoa 1.0.1", + "itoa", "ryu", "serde", ] @@ -1457,9 +1447,9 @@ dependencies = [ [[package]] name = "signal-hook" -version = "0.3.12" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c35dfd12afb7828318348b8c408383cf5071a086c1d4ab1c0f9840ec92dbb922" +checksum = "647c97df271007dcea485bb74ffdb57f2e683f1306c854f468a0c244badabf2d" dependencies = [ "libc", "signal-hook-registry", @@ -1571,9 +1561,9 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.82" +version = "1.0.85" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8daf5dd0bb60cbd4137b1b587d2fc0ae729bc07cf01cd70b36a1ed5ade3b9d59" +checksum = "a684ac3dcd8913827e18cd09a68384ee66c1de24157e3c556c9ab16d85695fb7" dependencies = [ "proc-macro2", "quote", @@ -1610,23 +1600,6 @@ dependencies = [ ] [[package]] -name = "time" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41effe7cfa8af36f439fac33861b66b049edc6f9a32331e2312660529c1c24ad" -dependencies = [ - "itoa 0.4.8", - "libc", - "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" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1667,9 +1640,9 @@ checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" [[package]] name = "version_check" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" +checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "vswhom" @@ -1982,9 +1955,9 @@ dependencies = [ [[package]] name = "x11-clipboard" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b397ace6e980510de59a4fe3d4c758dffab231d6d747ce9fa1aba6b6035d5f32" +checksum = "473068b7b80ac86a18328824f1054e5e007898c47b5bbc281bd7abe32bc3653c" dependencies = [ "xcb", ] @@ -2002,12 +1975,13 @@ dependencies = [ [[package]] name = "xcb" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62056f63138b39116f82a540c983cc11f1c90cd70b3d492a70c25eaa50bd22a6" +checksum = "771e2b996df720cd1c6dd9ff90f62d91698fd3610cc078388d0564bdd6622a9c" dependencies = [ "libc", "log", + "quick-xml", ] [[package]] diff --git a/alacritty/Cargo.toml b/alacritty/Cargo.toml index 67b18eb4..f6d0f6ed 100644 --- a/alacritty/Cargo.toml +++ b/alacritty/Cargo.toml @@ -20,7 +20,6 @@ version = "0.1.0" [dependencies] structopt = "0.3.22" log = { version = "0.4", features = ["std", "serde"] } -time = { version = "0.3.5", features = ["formatting", "local-offset", "macros"] } fnv = "1" serde = { version = "1", features = ["derive"] } serde_yaml = "0.8" 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<OnDemandLogFile>, stdout: Mutex<LineWriter<Stdout>>, event_proxy: Mutex<EventLoopProxy<Event>>, - 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<PathBuf> { @@ -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. |