File tree Expand file tree Collapse file tree 4 files changed +65
-1
lines changed
Expand file tree Collapse file tree 4 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -26,7 +26,6 @@ func (m *RequestMiddleware) Handle(next http.Handler) http.Handler {
2626 appCtx , err := m .ConfigSource .ProvideContext (r )
2727 if err != nil {
2828 if errors .Is (err , configsource .ErrAppNotFound ) {
29- logger .WithError (err ).Error ("app not found" )
3029 http .Error (w , configsource .ErrAppNotFound .Error (), http .StatusNotFound )
3130 } else {
3231 logger .WithError (err ).Error ("failed to resolve config" )
Original file line number Diff line number Diff line change 1+ package log
2+
3+ import (
4+ "context"
5+ "errors"
6+
7+ "github.com/sirupsen/logrus"
8+ )
9+
10+ // Ignore reports whether the entry should be logged.
11+ func Ignore (entry * logrus.Entry ) bool {
12+ if err , ok := entry .Data [logrus .ErrorKey ].(error ); ok {
13+ if errors .Is (err , context .Canceled ) {
14+ return true
15+ }
16+ }
17+
18+ return false
19+ }
Original file line number Diff line number Diff line change 1+ package log
2+
3+ import (
4+ "context"
5+ "fmt"
6+ "testing"
7+
8+ "github.com/sirupsen/logrus"
9+
10+ . "github.com/smartystreets/goconvey/convey"
11+ )
12+
13+ func TestIgnore (t * testing.T ) {
14+ Convey ("Ignore" , t , func () {
15+
16+ Convey ("Ignore entry with context.Canceled error" , func () {
17+ logger := logrus .New ()
18+ entry := logrus .NewEntry (logger )
19+ entry = entry .WithError (context .Canceled )
20+
21+ So (Ignore (entry ), ShouldBeTrue )
22+ })
23+
24+ Convey ("Ignore entry with wrapped context.Canceled error" , func () {
25+ logger := logrus .New ()
26+ entry := logrus .NewEntry (logger )
27+
28+ entry = entry .WithError (fmt .Errorf ("wrap: %w" , context .Canceled ))
29+
30+ So (Ignore (entry ), ShouldBeTrue )
31+ })
32+
33+ Convey ("Do not ignore any other entry" , func () {
34+ logger := logrus .New ()
35+ entry := logrus .NewEntry (logger )
36+
37+ So (Ignore (entry ), ShouldBeFalse )
38+ })
39+ })
40+ }
Original file line number Diff line number Diff line change 77 "github.com/getsentry/sentry-go"
88
99 "github.com/sirupsen/logrus"
10+
11+ "github.com/authgear/authgear-server/pkg/util/log"
1012)
1113
1214var LogHookLevels = []logrus.Level {
@@ -35,6 +37,10 @@ func (h *LogHook) Fire(entry *logrus.Entry) error {
3537 return nil
3638 }
3739
40+ if log .Ignore (entry ) {
41+ return nil
42+ }
43+
3844 event := makeEvent (entry )
3945 h .hub .CaptureEvent (event )
4046 return nil
You can’t perform that action at this time.
0 commit comments