Skip to content

Commit

Permalink
chore: shorten message field for unhandled panics
Browse files Browse the repository at this point in the history
  • Loading branch information
lzap authored and ezr-ondrej committed Sep 8, 2023
1 parent 8820f43 commit 341548d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
3 changes: 2 additions & 1 deletion internal/middleware/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
11 changes: 4 additions & 7 deletions pkg/worker/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 341548d

Please sign in to comment.