-
Notifications
You must be signed in to change notification settings - Fork 18k
proposal: log/slog: option to print msg key last #69620
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
Comments
Related Issues and Documentation
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
CC @jba I think the pain of making a change like this at this point outweighs the benefit. It would break too many working tests. |
As usual, the answer here is to write your own |
afaik most other structured loggers also put the message first since it contains the most important information. as mentioned above, filtering should be done with other tools if necessary |
I agree that JSONHandler isn't for people. But TextHandler output also brings up the same issue. Filtering logs may not always be feasible. Sometimes the log has to be read as is for establishing event timings from multiple goroutines or applications. Filtering logs will not give the complete picture. Say some container is running multiple go applications along with some non-go app which doesn't follow any logging pattern. Also, creating loggers using My point is that: |
Change https://go.dev/cl/619795 mentions this issue: |
Proposal Details
Consider the output of slog Text or JSON handler log outputs for below code
Output - JSONHandler
Although, this is easily machine parsable, but this doesn't look very human readable from one aspect.
When reading logs, the Attr added using
With
orWithGroup
are added in end. This makes it difficult to navigate and find next line of interest.The value for
msg
key is variable in length. As humans normally read from left to right, it takes effort to find the next common key attribute. E.g. in above case, the common key attribute isapp
which could be either alpha or beta.If msg is added last, all Attr added via
With
andWithGroup
will be better visually aligned. It will be easy to jump to next log for say "app": "alpha".If some flag in HandlerOptions is added like
AddMsgInLast
, it will make reading logs easier for cases likeThe text was updated successfully, but these errors were encountered: