aboutsummaryrefslogtreecommitdiff
path: root/alacritty/src/logging.rs
diff options
context:
space:
mode:
authorJames McCoy <jamessan@jamessan.com>2022-01-12 20:53:03 -0500
committerGitHub <noreply@github.com>2022-01-13 01:53:03 +0000
commit1c9fa73165f0bc97255dd10e64ad4c9b76ad1d02 (patch)
tree8727ead8eb3dbf89b1e3b5d7f331b09734338add /alacritty/src/logging.rs
parentfd7573d5d15ab229b233469fd9ab077158ece030 (diff)
downloadr-alacritty-1c9fa73165f0bc97255dd10e64ad4c9b76ad1d02.tar.gz
r-alacritty-1c9fa73165f0bc97255dd10e64ad4c9b76ad1d02.tar.bz2
r-alacritty-1c9fa73165f0bc97255dd10e64ad4c9b76ad1d02.zip
Update time crate to 0.3.5
Due to unsoundness issues (c.f., time-rs/time#380 and time-rs/time#293), determining the local timezone can only happen while single-threaded. Determine the timezone early in startup and apply the offset to the UTC timestamp before formatting.
Diffstat (limited to 'alacritty/src/logging.rs')
-rw-r--r--alacritty/src/logging.rs19
1 files changed, 15 insertions, 4 deletions
diff --git a/alacritty/src/logging.rs b/alacritty/src/logging.rs
index 56ed4ab5..0ed37220 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};
@@ -41,6 +43,7 @@ pub struct Logger {
logfile: Mutex<OnDemandLogFile>,
stdout: Mutex<LineWriter<Stdout>>,
event_proxy: Mutex<EventLoopProxy<Event>>,
+ tz_offset: UtcOffset,
}
impl Logger {
@@ -48,7 +51,12 @@ 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) }
+ Logger {
+ logfile,
+ stdout,
+ event_proxy: Mutex::new(event_proxy),
+ tz_offset: UtcOffset::current_local_offset().expect("local timezone offset"),
+ }
}
fn file_path(&self) -> Option<PathBuf> {
@@ -108,7 +116,7 @@ impl log::Log for Logger {
}
// Create log message for the given `record` and `target`.
- let message = create_log_message(record, target);
+ let message = create_log_message(record, target, self.tz_offset);
if let Ok(mut logfile) = self.logfile.lock() {
// Write to logfile.
@@ -127,8 +135,11 @@ impl log::Log for Logger {
fn flush(&self) {}
}
-fn create_log_message(record: &log::Record<'_>, target: &str) -> String {
- let now = time::strftime("%F %T.%f", &time::now()).unwrap();
+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);
// Alignment for the lines after the first new line character in the payload. We don't deal