You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This assumes that context helper
functions (#213) for slog will not get
merged. If that is the consensus, then this documentation should be the last
missing piece for slog support in logr.
Copy file name to clipboardExpand all lines: README.md
+86-1Lines changed: 86 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -94,7 +94,7 @@ logr design but also left out some parts and changed others:
94
94
95
95
The high-level slog API is explicitly meant to be one of many different APIs
96
96
that can be layered on top of a shared `slog.Handler`. logr is one such
97
-
alternative API, with interoperability provided by the [`slogr`](slogr)
97
+
alternative API, with [interoperability](#slog-interoperability) provided by the [`slogr`](slogr)
98
98
package.
99
99
100
100
### Inspiration
@@ -142,6 +142,91 @@ There are implementations for the following logging libraries:
142
142
-**github.com/go-kit/log**: [gokitlogr](https://github.com/tonglil/gokitlogr) (also compatible with github.com/go-kit/kit/log since v0.12.0)
143
143
-**bytes.Buffer** (writing to a buffer): [bufrlogr](https://github.com/tonglil/buflogr) (useful for ensuring values were logged, like during testing)
144
144
145
+
## slog interoperability
146
+
147
+
Interoperability goes both ways, using the `logr.Logger` API with a `slog.Handler`
148
+
and using the `slog.Logger` API with a `logr.LogSink`. [slogr](./slogr) provides `NewLogr` and
149
+
`NewSlogHandler` API calls to convert between a `logr.Logger` and a `slog.Handler`.
150
+
As usual, `slog.New` can be used to wrap such a `slog.Handler` in the high-level
151
+
slog API. `slogr` itself leaves that to the caller.
152
+
153
+
## Using a `logr.Sink` as backend for slog
154
+
155
+
Ideally, a logr sink implementation should support both logr and slog by
156
+
implementing both the normal logr interface(s) and `slogr.SlogSink`. Because
157
+
of a conflict in the parameters of the common `Enabled` method, it is [not
158
+
possible to implement both slog.Handler and logr.Sink in the same
0 commit comments