Skip to content

Commit e06ac33

Browse files
committed
🐛 SetLogger should work with nil sinks
Signed-off-by: Vince Prignano <vincepri@redhat.com>
1 parent 30eae58 commit e06ac33

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pkg/log/deleg.go

+3
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,9 @@ func (l *delegatingLogSink) WithValues(tags ...interface{}) logr.LogSink {
188188
// provided, instead of the temporary initial one, if this method
189189
// has not been previously called.
190190
func (l *delegatingLogSink) Fulfill(actual logr.LogSink) {
191+
if actual == nil {
192+
actual = NullLogSink{}
193+
}
191194
if l.promise != nil {
192195
l.promise.Fulfill(actual)
193196
}

pkg/log/log_test.go

+8
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,14 @@ var _ = Describe("logging", func() {
286286
logInfo{msg: "msg 2"},
287287
))
288288
})
289+
290+
It("should handle nil sinks", func() {
291+
By("fulfilling once")
292+
delegLog.Fulfill(logr.Discard().GetSink())
293+
By("grabbing a sub-logger and logging")
294+
l1 := logr.New(delegLog).WithName("nilsink").WithValues("newtag", "newvalue2")
295+
l1.Info("test")
296+
})
289297
})
290298

291299
Describe("logger from context", func() {

0 commit comments

Comments
 (0)