-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
65 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package log | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
|
||
"github.com/sirupsen/logrus" | ||
) | ||
|
||
// Ignore reports whether the entry should be logged. | ||
func Ignore(entry *logrus.Entry) bool { | ||
if err, ok := entry.Data[logrus.ErrorKey].(error); ok { | ||
if errors.Is(err, context.Canceled) { | ||
return true | ||
} | ||
} | ||
|
||
return false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package log | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/sirupsen/logrus" | ||
|
||
. "github.com/smartystreets/goconvey/convey" | ||
) | ||
|
||
func TestIgnore(t *testing.T) { | ||
Convey("Ignore", t, func() { | ||
|
||
Convey("Ignore entry with context.Canceled error", func() { | ||
logger := logrus.New() | ||
entry := logrus.NewEntry(logger) | ||
entry = entry.WithError(context.Canceled) | ||
|
||
So(Ignore(entry), ShouldBeTrue) | ||
}) | ||
|
||
Convey("Ignore entry with wrapped context.Canceled error", func() { | ||
logger := logrus.New() | ||
entry := logrus.NewEntry(logger) | ||
|
||
entry = entry.WithError(fmt.Errorf("wrap: %w", context.Canceled)) | ||
|
||
So(Ignore(entry), ShouldBeTrue) | ||
}) | ||
|
||
Convey("Do not ignore any other entry", func() { | ||
logger := logrus.New() | ||
entry := logrus.NewEntry(logger) | ||
|
||
So(Ignore(entry), ShouldBeFalse) | ||
}) | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters