Skip to content

Conversation

@tisonkun
Copy link
Contributor

Thanks to @kemingy's report in #194, and I was writing a PR as in mosecorg/mosec#680.

Although I think we may have another layout to format in JSON format like what tracing does, it is reasonable to have a customizable timestamp format function here because users' format preferences can be quite different.

See also @nine9ths in #169 where we come with the current default.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds support for customizable timestamp formatting functions in both text and JSON layouts, allowing users to define their own timestamp format instead of being limited to the default ISO 8601 format. The change also includes a refactoring where the timezone field is renamed from tz to timezone for better clarity.

Key changes:

  • Added a timestamp_format field to both TextLayout and JsonLayout that accepts a user-defined formatting function
  • Renamed the tz field to timezone in both layouts for improved readability
  • Extracted the default timestamp formatting logic into a default_timestamp_format function

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.

File Description
layouts/text/src/lib.rs Added customizable timestamp format function support, renamed timezone field, and refactored timestamp formatting logic
layouts/json/src/lib.rs Added customizable timestamp format function support, renamed timezone field, simplified serialization by removing custom timestamp serializer

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: tison <wander4096@gmail.com>
Signed-off-by: tison <wander4096@gmail.com>
@tisonkun tisonkun requested a review from andylokandy December 18, 2025 12:46
Self {
colors: LevelColor::default(),
no_color: false,
timezone: TimeZone::system(),
Copy link
Contributor Author

@tisonkun tisonkun Dec 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I hope avoiding calling TimeZone::system() or TimeZone::clone() on every logging record could improve performance a bit.

@tisonkun tisonkun merged commit 0956b0d into main Dec 19, 2025
10 checks passed
@tisonkun tisonkun deleted the timestamp-format branch December 19, 2025 00:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants