|
@@ -1,34 +1,14 @@
|
|
|
package fslog
|
|
|
|
|
|
import (
|
|
|
- "bytes"
|
|
|
ginzap "github.com/gin-contrib/zap"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
- "go.uber.org/zap"
|
|
|
- "go.uber.org/zap/zapcore"
|
|
|
- "io"
|
|
|
"time"
|
|
|
)
|
|
|
|
|
|
func GinLogger() gin.HandlerFunc {
|
|
|
lazyInitialize()
|
|
|
- return ginzap.GinzapWithConfig(logger, &ginzap.Config{
|
|
|
- UTC: true,
|
|
|
- TimeFormat: time.RFC3339,
|
|
|
- Context: func(c *gin.Context) []zapcore.Field {
|
|
|
- var buf bytes.Buffer
|
|
|
-
|
|
|
- tee := io.TeeReader(c.Request.Body, &buf)
|
|
|
- body, err := io.ReadAll(tee)
|
|
|
- if err != nil {
|
|
|
- return make([]zapcore.Field, 0)
|
|
|
- }
|
|
|
-
|
|
|
- c.Request.Body = io.NopCloser(&buf)
|
|
|
-
|
|
|
- return []zapcore.Field{zap.String("body", string(body))}
|
|
|
- },
|
|
|
- })
|
|
|
+ return ginzap.Ginzap(logger, time.RFC3339, true)
|
|
|
}
|
|
|
|
|
|
func GinRecovery() gin.HandlerFunc {
|