日志记录上下文

This commit is contained in:
xugo
2025-08-11 19:03:29 +08:00
parent ffd2fc2e27
commit 4b84ad30d2
11 changed files with 26 additions and 26 deletions
+1 -1
View File
@@ -39,7 +39,7 @@ func setupRouter(r *gin.Engine, uc *Usecase) {
// 格式化输出到控制台,然后记录到日志
// 此处不做 recover,底层 http.server 也会 recover,但不会输出方便查看的格式
gin.CustomRecovery(func(c *gin.Context, err any) {
slog.Error("panic", "err", err, "stack", string(debug.Stack()))
slog.ErrorContext(c.Request.Context(), "panic", "err", err, "stack", string(debug.Stack()))
c.AbortWithStatus(http.StatusInternalServerError)
}),
web.Metrics(),