Skip to content

Commit 859950b

Browse files
committed
Add logrus safe recoverer
1 parent c198c4f commit 859950b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

safe/logrus/go.mod

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module github.com/dsxack/go/safe/logrus
2+
3+
go 1.15
4+
5+
require (
6+
github.com/dsxack/go/v2 v2.0.0
7+
github.com/sirupsen/logrus v1.6.0
8+
)

safe/logrus/recover.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package logrus
2+
3+
import (
4+
"github.com/dsxack/go/v2/safe"
5+
"github.com/sirupsen/logrus"
6+
"runtime/debug"
7+
)
8+
9+
func init() {
10+
safe.DefaultRecover = RecoverLogger
11+
}
12+
13+
func RecoverLogger(err interface{}) {
14+
logrus.Errorf("Error in Go routine: %s\nStack: %s", err, debug.Stack())
15+
}

0 commit comments

Comments
 (0)