From e17a5c14126308c1f7c0fac1239a69a6e8c4ec54 Mon Sep 17 00:00:00 2001 From: bestgopher <84328409@qq.com> Date: Fri, 23 Aug 2024 02:56:49 +0800 Subject: [PATCH] Fix log timestamps not using local timezone (#16400) Get time offset by time crate will fail if there are mutli threads. So call `config_builder.set_time_offset_to_local()` is useless. Closes #16397 after: image Release Notes: - Fixed Local Timezone not showing Zed.log --- Cargo.lock | 1 + crates/zed/Cargo.toml | 1 + crates/zed/src/main.rs | 7 ++++++- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index b30f98a102..ec34c1651e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13913,6 +13913,7 @@ dependencies = [ "terminal_view", "theme", "theme_selector", + "time", "tree-sitter-md", "tree-sitter-rust", "ui", diff --git a/crates/zed/Cargo.toml b/crates/zed/Cargo.toml index 376f7feb66..3253fab4aa 100644 --- a/crates/zed/Cargo.toml +++ b/crates/zed/Cargo.toml @@ -97,6 +97,7 @@ tab_switcher.workspace = true supermaven.workspace = true task.workspace = true tasks_ui.workspace = true +time.workspace = true telemetry_events.workspace = true terminal_view.workspace = true theme.workspace = true diff --git a/crates/zed/src/main.rs b/crates/zed/src/main.rs index 727b11dbc4..e23ed69584 100644 --- a/crates/zed/src/main.rs +++ b/crates/zed/src/main.rs @@ -8,6 +8,7 @@ mod zed; use anyhow::{anyhow, Context as _, Result}; use assistant::PromptBuilder; +use chrono::Offset; use clap::{command, Parser}; use cli::FORCE_CLI_MODE_ENV_VAR_NAME; use client::{parse_zed_link, Client, DevServerToken, UserStore}; @@ -44,6 +45,7 @@ use std::{ sync::Arc, }; use theme::{ActiveTheme, SystemAppearance, ThemeRegistry, ThemeSettings}; +use time::UtcOffset; use util::{maybe, parse_env_output, ResultExt, TryFutureExt}; use uuid::Uuid; use welcome::{show_welcome_view, BaseKeymap, FIRST_OPEN}; @@ -886,7 +888,10 @@ fn init_logger() { let mut config_builder = ConfigBuilder::new(); config_builder.set_time_format_rfc3339(); - config_builder.set_time_offset_to_local().log_err(); + let local_offset = chrono::Local::now().offset().fix().local_minus_utc(); + if let Ok(offset) = UtcOffset::from_whole_seconds(local_offset) { + config_builder.set_time_offset(offset); + } #[cfg(target_os = "linux")] {