From 341548d5f2645489700989b6727b0925688eb8c3 Mon Sep 17 00:00:00 2001 From: Lukas Zapletal Date: Fri, 8 Sep 2023 09:42:06 +0200 Subject: [PATCH] chore: shorten message field for unhandled panics --- internal/middleware/logger.go | 3 ++- pkg/worker/redis.go | 11 ++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/internal/middleware/logger.go b/internal/middleware/logger.go index c98fc9d3..e42b7a51 100644 --- a/internal/middleware/logger.go +++ b/internal/middleware/logger.go @@ -55,7 +55,8 @@ func LoggerMiddleware(rootLogger *zerolog.Logger) func(next http.Handler) http.H log.Error(). Bool("panic", true). Int("status", panicStatus). - Msgf("Unhandled panic: %s\n%s", rec, debug.Stack()) + Bytes("stacktrace", debug.Stack()). + Msgf("Unhandled panic in API: %s", rec) http.Error(ww, http.StatusText(panicStatus), panicStatus) } diff --git a/pkg/worker/redis.go b/pkg/worker/redis.go index c3060934..bb0fa30f 100644 --- a/pkg/worker/redis.go +++ b/pkg/worker/redis.go @@ -165,13 +165,10 @@ func (w *RedisWorker) dequeueLoop(ctx context.Context, i, total int) { func recoverAndLog(ctx context.Context) { if rec := recover(); rec != nil { - logger := zerolog.Ctx(ctx).Error() - - if err, ok := rec.(error); ok { - logger.Err(err).Stack().Msg("Job queue panic") - } else { - logger.Msgf("Error during job handling: %v, stacktrace: %s", rec, debug.Stack()) - } + zerolog.Ctx(ctx).Error(). + Bool("panic", true). + Bytes("stacktrace", debug.Stack()). + Msgf("Unhandled panic in worker: %s", rec) } }