Repository navigation
Keep .Message raw with --timestamps; expose timestamp as .Timestamp - #372
Merged
Merged
Conversation
s3onghyun
requested review from
floryut,
rkmathi,
superbrothers and
tksm
as code owners
June 18, 2026 12:23
tksm
approved these changes
Jun 18, 2026
tksm
left a comment
Contributor
There was a problem hiding this comment.
LGTM 🥇 Could you rebase onto the latest master?
With --timestamps, the timestamp was prepended onto the log content that
becomes .Message, so template helpers that parse .Message as JSON
(extractJSONParts, parseJSON, prettyJSON, extjson) failed with
'invalid character ... after top-level value'.
Keep .Message as the raw log line and expose the timestamp as a new
.Timestamp template field. The built-in default/raw templates render
'{{if .Timestamp}}{{.Timestamp}} {{end}}{{.Message}}', so visible output is
unchanged when --timestamps is on and byte-identical when off.
Closes #342
Signed-off-by: Seonghyun Hong <[email protected]>
s3onghyun
force-pushed
the
342-timestamps-message
branch
from
June 18, 2026 13:50
89dc474 to
05813e4
Compare
Contributor
Author
|
Thanks for the review! Rebased onto the latest master and force-pushed. Tests still pass ( |
Contributor
|
Thanks for your contribution! |
1 task
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.
Fixes #342.
Problem
With
--timestamps, stern prepends the timestamp onto the log content that becomes.Message. So template helpers that parse.Messageas JSON —extractJSONParts,parseJSON,tryParseJSON,prettyJSON,extjson— receive2023-... {"...":...}instead of{"...":...}and fail withinvalid character '<digit>' after top-level value(exactly the error in #342). The README documents.Messageas "the log message itself", so this is a contract violation, and there was no separate field to get the timestamp from.Fix
Keep
.Messageraw and expose the timestamp as a new.Timestamptemplate field:Timestampto theLogstruct;consumeLineno longer mutates the content, it passes the timestamp through tosprint.defaultandrawtemplates render{{if .Timestamp}}{{.Timestamp}} {{end}}{{.Message}}— visible output is unchanged when--timestampsis on, and byte-identical when off (empty field)..Timestampin the README.Testing
Added
TestConsumeStreamTailTimestamp: with--timestamps,{{.Message}}stays raw JSON and{{.Timestamp}}carries the timestamp. Fails before the fix (.Messagepolluted;.Timestampundefined), passes after.go test ./...green.