Skip to content

Commit

Permalink
Merge pull request #2367 from vincepri/fix-deleg-null
Browse files Browse the repository at this point in the history
🐛 SetLogger should work with nil sinks
  • Loading branch information
k8s-ci-robot committed Jun 2, 2023
2 parents 30eae58 + e06ac33 commit 30dea34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/log/deleg.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ func (l *delegatingLogSink) WithValues(tags ...interface{}) logr.LogSink {
// provided, instead of the temporary initial one, if this method
// has not been previously called.
func (l *delegatingLogSink) Fulfill(actual logr.LogSink) {
if actual == nil {
actual = NullLogSink{}
}
if l.promise != nil {
l.promise.Fulfill(actual)
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/log/log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,14 @@ var _ = Describe("logging", func() {
logInfo{msg: "msg 2"},
))
})

It("should handle nil sinks", func() {
By("fulfilling once")
delegLog.Fulfill(logr.Discard().GetSink())
By("grabbing a sub-logger and logging")
l1 := logr.New(delegLog).WithName("nilsink").WithValues("newtag", "newvalue2")
l1.Info("test")
})
})

Describe("logger from context", func() {
Expand Down

0 comments on commit 30dea34

Please sign in to comment.