Skip to content

fix: don't drop user keyvals named like reserved keys#211

Open
c-tonneslan wants to merge 1 commit into
charmbracelet:mainfrom
c-tonneslan:fix/keyval-reserved-names
Open

fix: don't drop user keyvals named like reserved keys#211
c-tonneslan wants to merge 1 commit into
charmbracelet:mainfrom
c-tonneslan:fix/keyval-reserved-names

Conversation

@c-tonneslan

Copy link
Copy Markdown

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.

Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Keyval named level not working

1 participant