This release dramatically improves interoperability with Go's log/slog package. In particular, logr.NewContext and logr.NewContextWithSlogLogger use the same context key, which allows logr.FromContext and logr.FromContextAsSlogLogger to return logr.Logger or *slog.Logger respectively, including transparently converting each to the other as needed.
Functions logr/slogr.NewLogr and logr/slogr.ToSlogHandler have been superceded by logr.FromSlogHandler and logr.ToSlogHandler respectively, and type logr/slogr.SlogSink has been superceded by logr.SlogSink. All of the old names in logr/slogr remain, for compatibility.
Package logr/funcr now supports logr.SlogSink, meaning that it's output passes all but one of the Slog conformance tests (that exception being that funcr handles the timestamp itself).
Users who have a logr.Logger and need a *slog.Logger can call slog.New(logr.ToSlogHandler(...)) and all output will go through the same stack.
Users who have a *slog.Logger or slog.Handler can call logr.FromSlogHandler(...) and all output will go through the same stack.
What's Changed
- slog context support by @pohly in https://github.com/go-logr/logr/pull/237
- slog support: fix WithGroup + WithValues combination by @pohly in https://github.com/go-logr/logr/pull/243
- Add tests for context with slog by @thockin in https://github.com/go-logr/logr/pull/246
- sloghandler: unnamed groups should be inlined by @thockin in https://github.com/go-logr/logr/pull/245
- Add SlogSink support to funcr by @thockin in https://github.com/go-logr/logr/pull/241
- funcr: Add LogInfoLevel Option to skip logging level in the info log by @spacewander in https://github.com/go-logr/logr/pull/240
New Contributors
- @spacewander made their first contribution in https://github.com/go-logr/logr/pull/240
Full Changelog: https://github.com/go-logr/logr/compare/v1.3.0...v1.4.0