Skip to content

Commit 76d68e6

Browse files
authored
Merge pull request #8732 from pohly/error-logging
logging: warn about logger.V().Error
2 parents c6ba925 + 08ceb4d commit 76d68e6

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

contributors/devel/sig-instrumentation/migration-to-structured-logging.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,16 @@ functions need to be used:
190190
- `klog.ErrorS` -> `logger.Error`
191191
- `klog.InfoS` -> `logger.Info`
192192
- `klog.V().InfoS` -> `logger.V().Info`
193+
- `klog.V().ErrorS(err, ...)` -> `logger.V().Info(..., "err", err)`
193194

194195
In all of these cases, `logger` is a `logr.Logger` instance. `klog.Logger` is
195-
an alias for that type. Determining where that instance comes from is the main
196-
challenge when migrating code to contextual logging.
196+
an alias for that type. In contrast to klog, logr ignores verbosity for `Error`
197+
calls and always emits the log. The semantic equivalent of `klog.V().ErrorS` is
198+
therefore an `Info` call where the error is represented as a key/value pair.
197199

198-
Several new klog functions help with that:
200+
Determining where the `Logger` instance comes from is the main challenge when
201+
migrating code to contextual logging. Several new klog functions help with
202+
that:
199203

200204
- [`klog.FromContext`](https://pkg.go.dev/k8s.io/klog/v2#FromContext)
201205
- [`klog.Background`](https://pkg.go.dev/k8s.io/klog/v2#Background)

0 commit comments

Comments
 (0)