53 lines
1.6 KiB
Diff
53 lines
1.6 KiB
Diff
From 67f99391d25fd1108e15887b33df2e7bf19b90ef Mon Sep 17 00:00:00 2001
|
|
From: licunlong <licunlong1@huawei.com>
|
|
Date: Thu, 29 Jun 2023 10:33:27 +0800
|
|
Subject: [PATCH] fix: use localtime instead of UTC
|
|
|
|
---
|
|
libs/basic/Cargo.toml | 2 +-
|
|
libs/basic/src/logger.rs | 8 ++++++--
|
|
2 files changed, 7 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/libs/basic/Cargo.toml b/libs/basic/Cargo.toml
|
|
index b7d343c..42ac3ab 100644
|
|
--- a/libs/basic/Cargo.toml
|
|
+++ b/libs/basic/Cargo.toml
|
|
@@ -21,7 +21,7 @@ lazy_static = "1.4.0"
|
|
bitflags = "1.3.2"
|
|
pkg-config = "0.3"
|
|
rand = "0.4.6"
|
|
-time = {version = "=0.3.10", features = ["formatting", "macros"] }
|
|
+time = {version = "=0.3.10", features = ["formatting", "macros", "local-offset"] }
|
|
constants = { path = "../constants"}
|
|
|
|
[dev-dependencies]
|
|
diff --git a/libs/basic/src/logger.rs b/libs/basic/src/logger.rs
|
|
index 83fce0e..ae12c36 100644
|
|
--- a/libs/basic/src/logger.rs
|
|
+++ b/libs/basic/src/logger.rs
|
|
@@ -36,7 +36,7 @@ use log4rs::{
|
|
encode::pattern::PatternEncoder,
|
|
};
|
|
use nix::libc;
|
|
-use time::UtcOffset;
|
|
+use time::macros::offset;
|
|
|
|
use crate::Error;
|
|
|
|
@@ -69,7 +69,11 @@ impl log::Log for LogPlugin {
|
|
}
|
|
|
|
fn write_msg_common(writer: &mut impl Write, module: &str, msg: String) {
|
|
- let now = time::OffsetDateTime::now_utc().to_offset(UtcOffset::UTC);
|
|
+ let now = match time::OffsetDateTime::now_local() {
|
|
+ Ok(v) => v,
|
|
+ Err(_) => time::OffsetDateTime::now_utc().to_offset(offset!(+8)),
|
|
+ };
|
|
+
|
|
let format = time::macros::format_description!("[year]-[month]-[day] [hour]:[minute]:[second]");
|
|
let now = match now.format(&format) {
|
|
Err(_) => "[unknown time]".to_string(),
|
|
--
|
|
2.33.0
|
|
|