mirror of
https://github.com/Rudi9719/loggy.git
synced 2026-09-13 15:11:35 +00:00
Added a panic recovery func to log panics then continue execution
This commit is contained in:
@@ -209,6 +209,13 @@ func (l Logger) LogMsg(msg Log) {
|
|||||||
go handleLog(l, msg)
|
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
|
// Create a new logger instance and pass it
|
||||||
func NewLogger(opts LogOpts) Logger {
|
func NewLogger(opts LogOpts) Logger {
|
||||||
if opts.Level == 0 {
|
if opts.Level == 0 {
|
||||||
|
|||||||
Reference in New Issue
Block a user