feat: support customizable timestamp format function#204
Merged
Conversation
There was a problem hiding this comment.
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_formatfield to bothTextLayoutandJsonLayoutthat accepts a user-defined formatting function - Renamed the
tzfield totimezonein both layouts for improved readability - Extracted the default timestamp formatting logic into a
default_timestamp_formatfunction
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>
5b6b0c0 to
93909d0
Compare
Signed-off-by: tison <wander4096@gmail.com>
tisonkun
commented
Dec 18, 2025
| Self { | ||
| colors: LevelColor::default(), | ||
| no_color: false, | ||
| timezone: TimeZone::system(), |
Contributor
Author
There was a problem hiding this comment.
I hope avoiding calling TimeZone::system() or TimeZone::clone() on every logging record could improve performance a bit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.