Skip to content

Commit

Permalink
perf: Optimize the Zoned::now().with_time_zone (#52)
Browse files Browse the repository at this point in the history
  • Loading branch information
1996fanrui committed Aug 14, 2024
1 parent 954894a commit fc0f68d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/layout/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use std::fmt::Arguments;

use jiff::tz::TimeZone;
use jiff::Timestamp;
use jiff::Zoned;
use log::Record;
use serde::Serialize;
Expand Down Expand Up @@ -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(),
Expand Down
3 changes: 2 additions & 1 deletion src/layout/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit fc0f68d

Please sign in to comment.