From ca1047490f8655c9b68545cb986044830db32fd4 Mon Sep 17 00:00:00 2001 From: Dmitriy Smotrov Date: Tue, 15 Sep 2020 22:25:50 +0300 Subject: [PATCH] Add logrus safe recoverer --- safe/logrus/recover.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 safe/logrus/recover.go diff --git a/safe/logrus/recover.go b/safe/logrus/recover.go new file mode 100644 index 0000000..f4ec11a --- /dev/null +++ b/safe/logrus/recover.go @@ -0,0 +1,15 @@ +package logrus + +import ( + "github.com/dsxack/go/v2/safe" + "github.com/sirupsen/logrus" + "runtime/debug" +) + +func init() { + safe.DefaultRecover = RecoverLogger +} + +func RecoverLogger(err interface{}) { + logrus.Errorf("Error in Go routine: %s\nStack: %s", err, debug.Stack()) +}