-
Notifications
You must be signed in to change notification settings - Fork 2k
Add custom time format to JSON and TEXT logging #8168
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: AlexFenlon <[email protected]>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8168 +/- ##
==========================================
+ Coverage 53.08% 53.38% +0.29%
==========================================
Files 90 90
Lines 21778 21950 +172
==========================================
+ Hits 11561 11717 +156
- Misses 9740 9756 +16
Partials 477 477 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
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.
tiny tiny bit, but otherwise g2g
Key: slog.TimeKey, | ||
Value: slog.Int64Value(t.UnixNano()), | ||
} | ||
case "default": |
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.
this isn't needed here, because
- either we've already made sure that the time log format is one of the four allowed values, in which case if it's not the other three, then the switch's default arm is enough, or
- we haven't, and if we pass in some weird value like
iso8601
, which should not be allowed, that will also be ignored andrfc3339
will be printed, as per the original value coming from slog
imo we can extend |
Proposed changes
Add the option to change the timestamp of the logs in json and text format to unix in seconds, milliseconds and nanoseconds
eg. JSON with unix
{"time":"1755613721","level":"DEBUG","source":{"file":"controller.go","line":1019},"msg":"Syncing default/my-release-nginx-ingress-controller-7tj7f"}
default json
{"time":"2025-08-19T14:29:17.492029463Z","level":"DEBUG","source":{"file":"controller.go","line":1019},"msg":"Syncing default/my-release-nginx-ingress-controller-7tj7f"}
TEXT with unix-ms
time=1755619167305 level=DEBUG source=controller.go:1019 msg="Syncing default/my-release-nginx-ingress-controller-c828v"
default TEXT
time=2025-08-19T14:31:26.485Z level=DEBUG source=controller.go:1019 msg="Syncing default/my-release-nginx-ingress-controller-7tj7f"
Checklist
Before creating a PR, run through this checklist and mark each as complete.