|
@@ -18,16 +18,19 @@ func GinLogger() gin.HandlerFunc {
|
|
Context: func(c *gin.Context) []zapcore.Field {
|
|
Context: func(c *gin.Context) []zapcore.Field {
|
|
var body []byte
|
|
var body []byte
|
|
var buf bytes.Buffer
|
|
var buf bytes.Buffer
|
|
|
|
+ fields := make([]zapcore.Field, 0)
|
|
|
|
|
|
- tee := io.TeeReader(c.Request.Body, &buf)
|
|
|
|
- body, err := io.ReadAll(tee)
|
|
|
|
|
|
+ body, err := io.ReadAll(c.Request.Body)
|
|
if err != nil {
|
|
if err != nil {
|
|
return make([]zapcore.Field, 0)
|
|
return make([]zapcore.Field, 0)
|
|
}
|
|
}
|
|
|
|
|
|
- c.Request.Body = io.NopCloser(&buf)
|
|
|
|
|
|
+ if body != nil && len(body) != 0 {
|
|
|
|
+ fields = append(fields, zap.String("body", string(body)))
|
|
|
|
+ c.Request.Body = io.NopCloser(&buf)
|
|
|
|
+ }
|
|
|
|
|
|
- return []zapcore.Field{zap.String("body", string(body))}
|
|
|
|
|
|
+ return fields
|
|
},
|
|
},
|
|
})
|
|
})
|
|
}
|
|
}
|