aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src
diff options
context:
space:
mode:
authorChristian Duerr <contact@christianduerr.com>2022-01-13 06:36:22 +0100
committerGitHub <noreply@github.com>2022-01-13 08:36:22 +0300
commite38f51c6bd73999e4e36110ca21cdb473de00bd5 (patch)
treed021934781d35852667c3153feb2e69c18c9803a /alacritty/src
parent7398e9f8d129359b8590754b1944ef2ba5e76ab6 (diff)
downloadr-alacritty-e38f51c6bd73999e4e36110ca21cdb473de00bd5.tar.gz
r-alacritty-e38f51c6bd73999e4e36110ca21cdb473de00bd5.tar.bz2
r-alacritty-e38f51c6bd73999e4e36110ca21cdb473de00bd5.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.
Diffstat (limited to 'alacritty/src')
-rw-r--r--alacritty/src/logging.rs25
1 files changed, 9 insertions, 16 deletions
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.