Skip to content

Commit

Permalink
refactor: simplify strftime with precision format (#58)
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Aug 24, 2024
1 parent 266b9a8 commit 1263c7e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 6 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ rolling_file = ["dep:crossbeam-channel", "dep:parking_lot"]
[dependencies]
anyhow = { version = "1.0" }
colored = { version = "2.1" }
jiff = { version = "0.1.5" }
jiff = { version = "0.1.10" }
log = { version = "0.4", features = ["std", "kv_unstable"] }
paste = { version = "1.0" }

Expand Down Expand Up @@ -81,7 +81,7 @@ version = "0.12"
## Fastrace dependencies
[dependencies.fastrace]
optional = true
version = "0.7.1"
version = "0.7"

## Opentelemetry dependencies
[dependencies.opentelemetry]
Expand Down
2 changes: 1 addition & 1 deletion src/layout/json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn serialize_time_zone<S>(timestamp: &Zoned, serializer: S) -> Result<S::Ok, S::
where
S: serde::Serializer,
{
serializer.collect_str(&timestamp.strftime("%Y-%m-%dT%H:%M:%S.%6f%:z"))
serializer.collect_str(&format_args!("{timestamp:.6}"))
}

fn serialize_args<S>(args: &Arguments, serializer: S) -> Result<S::Ok, S::Error>
Expand Down
5 changes: 2 additions & 3 deletions src/layout/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,7 @@ impl TextLayout {
let time = match self.tz.clone() {
Some(tz) => Timestamp::now().to_zoned(tz),
None => Zoned::now(),
}
.strftime("%Y-%m-%dT%H:%M:%S.%6f%:z");
};
let level = if self.no_color {
ColoredString::from(record.level().to_string())
} else {
Expand All @@ -160,7 +159,7 @@ impl TextLayout {
let kvs = KvDisplay::new(record.key_values());

f(format_args!(
"{time} {level:>5} {module}: {file}:{line} {message}{kvs}"
"{time:.6} {level:>5} {module}: {file}:{line} {message}{kvs}"
))
}
}
Expand Down

0 comments on commit 1263c7e

Please sign in to comment.