mirror of
https://github.com/veops/oneterm.git
synced 2025-10-05 07:16:57 +08:00
feat(backend): replace JSON errors with user-friendly HTML error pages and reduce log noise
This commit is contained in:
@@ -16,12 +16,24 @@ func LoggerMiddleware() gin.HandlerFunc {
|
||||
ctx.Next()
|
||||
|
||||
cost := time.Since(start)
|
||||
logger.L().Info(ctx.Request.URL.String(),
|
||||
zap.String("method", ctx.Request.Method),
|
||||
zap.Int("status", ctx.Writer.Status()),
|
||||
zap.String("ip", ctx.ClientIP()),
|
||||
zap.Duration("cost", cost),
|
||||
)
|
||||
// Only log errors and slow requests
|
||||
status := ctx.Writer.Status()
|
||||
if status >= 400 || cost > 1*time.Second {
|
||||
logger.L().Info(ctx.Request.URL.String(),
|
||||
zap.String("method", ctx.Request.Method),
|
||||
zap.Int("status", status),
|
||||
zap.String("ip", ctx.ClientIP()),
|
||||
zap.Duration("cost", cost),
|
||||
)
|
||||
} else {
|
||||
// Normal requests use debug level to reduce log noise
|
||||
logger.L().Debug(ctx.Request.URL.String(),
|
||||
zap.String("method", ctx.Request.Method),
|
||||
zap.Int("status", status),
|
||||
zap.String("ip", ctx.ClientIP()),
|
||||
zap.Duration("cost", cost),
|
||||
)
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user