Skip to content

Commit

Permalink
log: Use local timezone in log timestamps (zed-industries#7079)
Browse files Browse the repository at this point in the history
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 <beniamin@zagan.be>
  • Loading branch information
osiewicz and Sethback authored Jan 30, 2024
1 parent e6ebe79 commit e756602
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions crates/zed/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;

Expand All @@ -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");
Expand Down

0 comments on commit e756602

Please sign in to comment.