From 4b6a003ed1f46e03ccb4ddb5d61b08039f4b87db Mon Sep 17 00:00:00 2001 From: Gregory Rudolph Date: Mon, 6 Apr 2020 08:12:23 -0400 Subject: [PATCH] Added a panic recovery func to log panics then continue execution --- loggy.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/loggy.go b/loggy.go index 898932b..d88bcb4 100644 --- a/loggy.go +++ b/loggy.go @@ -209,6 +209,13 @@ func (l Logger) LogMsg(msg Log) { go handleLog(l, msg) } +// PanicSafe() is a deferrable function to recover from a panic operation. +func (l Logger) PanicSafe() { + if r := recover(); r != nil { + l.LogCritical(fmt.Sprintf("Panic detected: %+v", r)) + } +} + // Create a new logger instance and pass it func NewLogger(opts LogOpts) Logger { if opts.Level == 0 {