Use local time for logger (#6132)

Signed-off-by: nibon7 <nibon7@163.com>
This commit is contained in:
nibon7 2022-07-26 19:20:35 +08:00 committed by GitHub
parent 8c675a0d31
commit f5856b0914
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,4 @@
use chrono::{DateTime, FixedOffset, Utc};
use chrono::{DateTime, Local};
use core::fmt;
use log::Level;
use log::LevelFilter;
@ -32,11 +32,8 @@ pub fn my_formatted_timed_builder() -> Builder {
});
let dt = match DateTime::parse_from_rfc3339(&f.timestamp_millis().to_string()) {
Ok(d) => d,
Err(_) => {
let n = Utc::now();
DateTime::<FixedOffset>::from(n)
}
Ok(d) => d.with_timezone(&Local),
Err(_) => Local::now(),
};
let time = dt.format("%Y-%m-%d %I:%M:%S%.3f %p");
writeln!(f, "{}|{}|{}|{}", time, level, target, record.args(),)