Browse Source

修改logger

yjp 1 year ago
parent
commit
d5814a2ee5
1 changed files with 2 additions and 6 deletions
  1. 2 6
      gin_logger.go

+ 2 - 6
gin_logger.go

@@ -18,19 +18,15 @@ 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)
 
 
 			body, err := io.ReadAll(c.Request.Body)
 			body, err := io.ReadAll(c.Request.Body)
 			if err != nil {
 			if err != nil {
 				return make([]zapcore.Field, 0)
 				return make([]zapcore.Field, 0)
 			}
 			}
 
 
-			if body != nil && len(body) != 0 {
-				fields = append(fields, zap.String("body", string(body)))
-				c.Request.Body = io.NopCloser(&buf)
-			}
+			c.Request.Body = io.NopCloser(&buf)
 
 
-			return fields
+			return []zapcore.Field{zap.String("body", string(body))}
 		},
 		},
 	})
 	})
 }
 }