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

Fix regression by handling nil logger correctly #507

Merged
merged 3 commits into from
Apr 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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