Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: built-in attributes are not grouped (#30)
* fix: built-in attributes are not grouped Built-in attributes are not considered part of a logger's group as specified by `WithGroup`. Doing so means that if a user makes a log statement like the following, log.WithGroup("foo").Info("bar") ReplaceAttr will be called with `groups = [foo]` for all built-in keys, and therefore the [included code sample][1] for creating a logger without the time key will not work. [1]: https://github.com/lmittmann/tint#customize-attributes This change fixes invocations of ReplaceAttr to call it with an empty groups slice for built-in attributes. This matches the behavior of `log/slog`'s default handlers which set `groups = nil` for the built-in attributes ([src][2]) before restoring it for non-built-ins ([src][3]). [2]: https://cs.opensource.google/go/go/+/refs/tags/go1.21.0:src/log/slog/handler.go;l=265-266 [3]: https://cs.opensource.google/go/go/+/refs/tags/go1.21.0:src/log/slog/handler.go;l=300-301 Includes tests for omitting all built-in attributes. * refactored test case --------- Co-authored-by: lmittmann <[email protected]>
- Loading branch information