From e7566026101b37ace3d5c989d2e38db20e4133e2 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Tue, 30 Jan 2024 20:18:39 +0100 Subject: [PATCH] log: Use local timezone in log timestamps (#7079) I'm gonna let it sit for a day in case anybody has any objections to that change. Release Notes: - Logs now use local timestamps instead of UTC-based timestamps --------- Co-authored-by: Beniamin --- crates/zed/src/main.rs | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 863bdd37120f7..ba651cf8e030a 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -9,6 +9,7 @@ use client::{Client, UserStore}; use collab_ui::channel_view::ChannelView; use db::kvp::KEY_VALUE_STORE; use editor::Editor; +use env_logger::Builder; use fs::RealFs; use futures::StreamExt; use gpui::{App, AppContext, AsyncAppContext, Context, SemanticVersion, Task}; @@ -483,7 +484,29 @@ fn init_paths() { fn init_logger() { if stdout_is_a_pty() { - env_logger::init(); + Builder::new() + .format(|buf, record| { + use env_logger::fmt::Color; + + let subtle = buf + .style() + .set_color(Color::Black) + .set_intense(true) + .clone(); + write!(buf, "{}", subtle.value("["))?; + write!( + buf, + "{} ", + chrono::Local::now().format("%Y-%m-%dT%H:%M:%S%:z") + )?; + write!(buf, "{:<5}", buf.default_styled_level(record.level()))?; + if let Some(path) = record.module_path() { + write!(buf, " {}", path)?; + } + write!(buf, "{}", subtle.value("]"))?; + writeln!(buf, " {}", record.args()) + }) + .init(); } else { let level = LevelFilter::Info; @@ -503,7 +526,8 @@ fn init_logger() { .expect("could not open logfile"); let config = ConfigBuilder::new() - .set_time_format_str("%Y-%m-%dT%T") //All timestamps are UTC + .set_time_format_str("%Y-%m-%dT%T%:z") + .set_time_to_local(true) .build(); simplelog::WriteLogger::init(level, config, log_file).expect("could not initialize logger");