Jelajahi Sumber

修改logger

yjp 1 tahun lalu
induk
melakukan
d5814a2ee5
1 mengubah file dengan 2 tambahan dan 6 penghapusan
  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 {
 			var body []byte
 			var buf bytes.Buffer
-			fields := make([]zapcore.Field, 0)
 
 			body, err := io.ReadAll(c.Request.Body)
 			if err != nil {
 				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))}
 		},
 	})
 }