From fc0f68d92b4e3ee4ed5faf1a2a074ad730d3d93c Mon Sep 17 00:00:00 2001 From: Rui Fan <1996fanrui@gmail.com> Date: Wed, 14 Aug 2024 21:29:43 +0800 Subject: [PATCH] perf: Optimize the Zoned::now().with_time_zone (#52) --- src/layout/json.rs | 3 ++- src/layout/text.rs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/layout/json.rs b/src/layout/json.rs index 89f9848..36174f4 100644 --- a/src/layout/json.rs +++ b/src/layout/json.rs @@ -15,6 +15,7 @@ use std::fmt::Arguments; use jiff::tz::TimeZone; +use jiff::Timestamp; use jiff::Zoned; use log::Record; use serde::Serialize; @@ -97,7 +98,7 @@ impl JsonLayout { let record_line = RecordLine { timestamp: match self.tz.clone() { - Some(tz) => Zoned::now().with_time_zone(tz), + Some(tz) => Timestamp::now().to_zoned(tz), None => Zoned::now(), }, level: record.level().as_str(), diff --git a/src/layout/text.rs b/src/layout/text.rs index aacc4ad..3b1cf87 100644 --- a/src/layout/text.rs +++ b/src/layout/text.rs @@ -18,6 +18,7 @@ use colored::Color; use colored::ColoredString; use colored::Colorize; use jiff::tz::TimeZone; +use jiff::Timestamp; use jiff::Zoned; use log::Level; @@ -135,7 +136,7 @@ impl TextLayout { F: Fn(Arguments) -> anyhow::Result<()>, { let time = match self.tz.clone() { - Some(tz) => Zoned::now().with_time_zone(tz), + Some(tz) => Timestamp::now().to_zoned(tz), None => Zoned::now(), } .strftime("%Y-%m-%dT%H:%M:%S.%6f%:z");