fix: don't drop user keyvals named like reserved keys#211
Open
c-tonneslan wants to merge 1 commit into
Open
Conversation
Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
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.
Closes #166.
When a user passed a keyval whose key matched one of the reserved names (`level`, `ts`, `caller`, `prefix`, `msg`) but with a value of a different type than the internal logger uses, the entry was silently dropped:
```go
log.Info("test", "level", "foo", "anything-else", "bar")
// before: INFO test anything-else=bar
// after: INFO test level=foo anything-else=bar
```
Both the text and JSON formatters had the same shape — `case LevelKey:` matched the key, the inner type assertion failed, and the switch fell off the end without writing anything or falling through to the default keyval rendering.
Now each special case only takes ownership of the entry when its type assertion succeeds; otherwise the default path renders it as a regular keyval.
Test plan
```
go test ./...
go test -race ./...
```
Added `TestKeyvalNamedAsReservedKey` covering both text and JSON formatters with the case from the issue.