From cf8fc32c318c510afc40fec2d9bdcc8ec4590eed Mon Sep 17 00:00:00 2001 From: Victor Brekenfeld Date: Sat, 5 Feb 2022 21:26:01 +0100 Subject: [PATCH] fix TestLogger --- src/loggers/testlog.rs | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/loggers/testlog.rs b/src/loggers/testlog.rs index 2c616442..f62130f7 100644 --- a/src/loggers/testlog.rs +++ b/src/loggers/testlog.rs @@ -8,7 +8,7 @@ //! Module providing the TestLogger Implementation use super::logging::should_skip; -use crate::{Config, LevelPadding, SharedLogger}; +use crate::{config::TimeFormat, Config, LevelPadding, SharedLogger}; use log::{set_boxed_logger, set_max_level, LevelFilter, Log, Metadata, Record, SetLoggerError}; use std::thread; @@ -128,12 +128,18 @@ pub fn log(config: &Config, record: &Record<'_>) { #[inline(always)] pub fn write_time(config: &Config) { - let cur_time = if config.time_local { - chrono::Local::now().naive_local() + config.time_offset - } else { - chrono::Utc::now().naive_utc() + config.time_offset + use time::format_description::well_known::*; + + let time = time::OffsetDateTime::now_utc().to_offset(config.time_offset); + let res = match config.time_format { + TimeFormat::Rfc2822 => time.format(&Rfc2822), + TimeFormat::Rfc3339 => time.format(&Rfc3339), + TimeFormat::Custom(format) => time.format(&format), + }; + match res { + Ok(time) => println!("{} ", time), + Err(err) => panic!("Invalid time format: {}", err), }; - print!("{} ", cur_time.format(&*config.time_format)); } #[inline(always)]