Skip to content
This repository has been archived by the owner on May 23, 2024. It is now read-only.

Commit

Permalink
Fix regression by handling nil logger correctly (#507)
Browse files Browse the repository at this point in the history
  • Loading branch information
vprithvi authored Apr 28, 2020
1 parent 93622f9 commit e7a6498
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
3 changes: 3 additions & 0 deletions log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ type DebugLogger interface {
// If the provided Logger doesn't satisfy the interface, a logger with debug
// disabled is returned
func DebugLogAdapter(logger Logger) DebugLogger {
if logger == nil {
return nil
}
if debugLogger, ok := logger.(DebugLogger); ok {
return debugLogger
}
Expand Down
4 changes: 4 additions & 0 deletions log/logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ func TestDebugLogAdapter_ReturnSameIfDebugLogger(t *testing.T) {
assert.Same(t, NullLogger, DebugLogAdapter(NullLogger))
}

func TestDebugLogAdapter_HandleNil(t *testing.T) {
assert.Nil(t, DebugLogAdapter(nil))
}

type mockLogger struct {
errorCalled bool
infoCalled bool
Expand Down

0 comments on commit e7a6498

Please sign in to comment.