Repository navigation
Resolve panic in the console writer for short level field values - #665
Merged
Merged
Conversation
zerolog for Short level Field Valueszerolog for short level field values
rs
reviewed
Apr 10, 2024
| } | ||
|
|
||
| func consoleDefaultFormatLevel(noColor bool) Formatter { | ||
| prefix := func(s string) string { |
Comment on lines
+420
to
+424
| if len(ll) == 0 { | ||
| l = unknownLevel | ||
| } else { | ||
| l = strings.ToUpper(prefix(ll)) | ||
| } |
Owner
There was a problem hiding this comment.
What about making all this logic a function instead of just prefix?
ndk
marked this pull request as draft
April 10, 2024 07:38
ndk
marked this pull request as ready for review
April 10, 2024 07:38
zerolog for short level field valueslevel field values
rs
reviewed
Apr 12, 2024
|
|
||
| func consoleDefaultFormatLevel(noColor bool) Formatter { | ||
| const unknownLevel = "???" | ||
| stripLevel := func(ll string) string { |
Owner
There was a problem hiding this comment.
Any reason for this function not to be top level?
Contributor
Author
There was a problem hiding this comment.
By default, I try to reduce the scope of visibility as much as possible (especially when the stuff is too specific and doesn't look like it's to be reused elsewhere), but I don't have any strong preferences. So, if you think it's better to extract it from the function to the package I'll do it promptly. :)
Owner
There was a problem hiding this comment.
I prefer smaller unit functions as they enhance readability and do not eliminate the possibility of inlining.
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.
This PR fixes an issue in the
zerologconsole writer. Specifying a non-typical value for thelevelfield, resulting in a serialized value of less than 3 bytes, causes a panic. For instance: