-
Notifications
You must be signed in to change notification settings - Fork 25
feat: support customizable timestamp format function #204
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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_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>
| Self { | ||
| colors: LevelColor::default(), | ||
| no_color: false, | ||
| timezone: TimeZone::system(), |
There was a problem hiding this comment.
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.
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.