ai cooking
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

capture panics in logger (#493)

Co-authored-by: paul miller <paul.miller>

authored by

Paul Miller
paul miller
and committed by
GitHub
d3ed392f 21539f4a

+20 -1
+20 -1
internal/logsetup/logger.go
··· 5 5 "fmt" 6 6 "log/slog" 7 7 "os" 8 + "runtime/debug" 8 9 9 10 "github.com/openclosed-dev/slogan/appinsights" 10 11 ) ··· 27 28 } 28 29 29 30 slog.SetDefault(slog.New(slog.NewMultiHandler(handlers...))) 30 - return closeFn, nil 31 + return recoverAndClose(ctx, closeFn), nil 32 + } 33 + 34 + func recoverAndClose(ctx context.Context, closeFn func()) func() { 35 + return func() { 36 + panicValue := recover() 37 + if panicValue != nil { 38 + slog.ErrorContext(ctx, "panic before logger flush", 39 + "panic", panicValue, 40 + "stack", string(debug.Stack()), 41 + ) 42 + } 43 + 44 + closeFn() 45 + 46 + if panicValue != nil { 47 + panic(panicValue) 48 + } 49 + } 31 50 }