Skip to content

Commit 18c884e

Browse files
committed
🐛 SetLogger should work with nil sinks
Signed-off-by: Vince Prignano <[email protected]>
1 parent 30eae58 commit 18c884e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-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

+7
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ func (f *fakeLogger) Enabled(level int) bool { return true }
9898
var _ = Describe("logging", func() {
9999

100100
Describe("top-level logger", func() {
101+
It("should be able to use logr.Discard", func() {
102+
SetLogger(logr.Discard())
103+
By("grabbing a sub-logger and logging")
104+
l1 := Log.WithName("runtimeLog").WithValues("newtag", "newvalue2")
105+
l1.Info("test")
106+
})
107+
101108
It("hold newly created loggers until a logger is set", func() {
102109
By("grabbing a new sub-logger and logging to it")
103110
l1 := Log.WithName("runtimeLog").WithValues("newtag", "newvalue1")

0 commit comments

Comments
 (0)