Skip to content
Closed
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
11 changes: 11 additions & 0 deletions log.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,3 +507,14 @@ func (l *Logger) should(lvl Level) bool {
}
return true
}

// Enabled returns true if the logger is not disabled.
func (l *Logger) Enabled() bool {
if l.w == nil {
return false
}
if l.level == Disabled || GlobalLevel() == Disabled {
return false
}
return true
}
3 changes: 3 additions & 0 deletions log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,9 @@ func TestLevel(t *testing.T) {
if got, want := decodeIfBinaryToString(out.Bytes()), ""; got != want {
t.Errorf("invalid log output:\ngot: %v\nwant: %v", got, want)
}
if log.Enabled() {
t.Errorf("expect log to be disabled")
}
})

t.Run("NoLevel/Disabled", func(t *testing.T) {
Expand Down