sysmaster/backport-fix-downgrade-the-time-crate-from-0.3.x-to-0.1.45.patch
huyubiao 8936fa02c5 sync patches from upstream,change the path of the unit,modify permissions for some directories and files
(cherry picked from commit ce9ff469b57f60130621bc293783bd3ac1fc92f2)
2023-08-05 18:15:53 +08:00

70 lines
2.1 KiB
Diff

From d50fcced7eea0ceabf74191d3de4d08420120a3a Mon Sep 17 00:00:00 2001
From: licunlong <licunlong1@huawei.com>
Date: Mon, 24 Jul 2023 19:12:16 +0800
Subject: [PATCH] fix: downgrade the time crate from 0.3.x to 0.1.45
---
libs/basic/Cargo.toml | 2 +-
libs/basic/src/logger.rs | 23 +++++++++++------------
2 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/libs/basic/Cargo.toml b/libs/basic/Cargo.toml
index 29f97a3..d0dd4fb 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.5", features = ["formatting", "macros", "local-offset"] }
+time = "=0.1.45"
constants = { path = "../constants"}
[dev-dependencies]
diff --git a/libs/basic/src/logger.rs b/libs/basic/src/logger.rs
index ae12c36..9f96316 100644
--- a/libs/basic/src/logger.rs
+++ b/libs/basic/src/logger.rs
@@ -36,7 +36,6 @@ use log4rs::{
encode::pattern::PatternEncoder,
};
use nix::libc;
-use time::macros::offset;
use crate::Error;
@@ -69,19 +68,19 @@ impl log::Log for LogPlugin {
}
fn write_msg_common(writer: &mut impl Write, module: &str, msg: String) {
- 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(),
- Ok(v) => v,
- };
+ let now = time::now();
+ let now_str = format!(
+ "{:0>4}-{:0>2}-{:0>2} {:0>2}:{:0>2}:{:0>2} ",
+ now.tm_year + 1900, /* tm_year is years since 1900 */
+ now.tm_mon + 1, /* tm_mon is months since Jan: [0, 11] */
+ now.tm_mday,
+ now.tm_hour,
+ now.tm_min,
+ now.tm_sec
+ );
/* 1. Write time */
- if let Err(e) = writer.write(format!("{now} ").as_bytes()) {
+ if let Err(e) = writer.write(now_str.as_bytes()) {
println!("Failed to log time message: {e}");
return;
}
--
2.33.0