|
|
@@ -6,10 +6,11 @@ import (
|
|
|
"time"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
- "github.com/runningwater/gohub/pkg/helpers"
|
|
|
- "github.com/runningwater/gohub/pkg/logger"
|
|
|
"github.com/spf13/cast"
|
|
|
"go.uber.org/zap"
|
|
|
+
|
|
|
+ "github.com/runningwater/gohub/pkg/helpers"
|
|
|
+ "github.com/runningwater/gohub/pkg/logger"
|
|
|
)
|
|
|
|
|
|
type responseBodyWriter struct {
|
|
|
@@ -45,10 +46,10 @@ func Logger() gin.HandlerFunc {
|
|
|
|
|
|
// 开始记录日志的逻辑
|
|
|
cost := time.Since(start)
|
|
|
- responStatus := c.Writer.Status()
|
|
|
+ responseStatus := c.Writer.Status()
|
|
|
|
|
|
logFields := []zap.Field{
|
|
|
- zap.Int("status", responStatus),
|
|
|
+ zap.Int("status", responseStatus),
|
|
|
zap.String("request", c.Request.Method+c.Request.URL.String()),
|
|
|
zap.String("query", c.Request.URL.RawQuery),
|
|
|
zap.String("ip", c.ClientIP()),
|
|
|
@@ -63,11 +64,11 @@ func Logger() gin.HandlerFunc {
|
|
|
logFields = append(logFields, zap.String("ResponseBody", w.body.String()))
|
|
|
}
|
|
|
|
|
|
- if responStatus > 400 && responStatus < 500 {
|
|
|
+ if responseStatus > 400 && responseStatus < 500 {
|
|
|
// 403 404 等客户端错误,使用 Warn 级别
|
|
|
- logger.Warn("HTTP Warning "+cast.ToString(responStatus), logFields...)
|
|
|
- } else if responStatus >= 500 && responStatus < 600 {
|
|
|
- logger.Error("HTTP Error "+cast.ToString(responStatus), logFields...)
|
|
|
+ logger.Warn("HTTP Warning "+cast.ToString(responseStatus), logFields...)
|
|
|
+ } else if responseStatus >= 500 && responseStatus < 600 {
|
|
|
+ logger.Error("HTTP Error "+cast.ToString(responseStatus), logFields...)
|
|
|
} else {
|
|
|
logger.Debug("HTTP Access Log", logFields...)
|
|
|
}
|