Skip to content

Commit

Permalink
DontLog does not wrap nil errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ungerik committed Jun 22, 2023
1 parent 69a94ec commit 190842c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ type LogDecisionMaker interface {
// of its ShouldLog method.
// If error does not unwrap to LogDecisionMaker
// and is not nil then ShouldLog returns true.
// If nil is passed as error, then ShouldLog returns false.
// A nil error results in false.
func ShouldLog(err error) bool {
if err == nil {
return false
Expand All @@ -38,7 +38,11 @@ func ShouldLog(err error) bool {

// DontLog wraps the passed error as LogDecisionMaker
// so that ShouldLog returns false.
// A nil error won't be wrapped but returned as nil.
func DontLog(err error) error {
if err == nil {
return nil
}
return dontLog{err}
}

Expand Down

0 comments on commit 190842c

Please sign in to comment.