Commit 8a00ec4
committed
🌱 Add ctrl.{LoggerFrom, LoggerInto}
Renames the current (unreleased at the time of writing)
LoggerFromContext to LoggerFrom, and adds a new alias named LoggerInto.
From a user standpoint these new aliases are really clear and
straightfoward, example:
```go
func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) {
log := ctrl.LoggerFrom(ctx)
```
This reads much better than ctrl.LoggerFromContext(ctx) which repeats
the context.
Another use case that this change solves is to enrich the logger with
more values, example:
```go
ctx = ctrl.LoggerInto(ctx, log.WithValues(...))
```
allows the ctx to still be the de-facto context, and the logger for the
inner reconciler function to still only accept ctx, without adding any
more parameters.
Signed-off-by: Vince Prignano <[email protected]>1 parent df9195b commit 8a00ec4
1 file changed
+7
-2
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
125 | 125 | | |
126 | 126 | | |
127 | 127 | | |
128 | | - | |
| 128 | + | |
129 | 129 | | |
130 | 130 | | |
131 | | - | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
132 | 137 | | |
133 | 138 | | |
134 | 139 | | |
| |||
0 commit comments