|
12345678910111213141516171819202122232425262728293031 |
- package mw
-
- import (
- "time"
-
- "github.com/gin-gonic/gin"
- "go.uber.org/zap"
-
- "applet/app/utils/logx"
- )
-
- // access log
- func AccessLog(c *gin.Context) {
- start := time.Now()
- c.Next()
- cost := time.Since(start)
-
- logx.Info(c.Request.URL.Path)
-
- logger := &zap.Logger{}
- logger.Info(c.Request.URL.Path,
- zap.Int("status", c.Writer.Status()),
- zap.String("method", c.Request.Method),
- zap.String("path", c.Request.URL.Path),
- zap.String("query", c.Request.URL.RawQuery),
- zap.String("ip", c.ClientIP()),
- zap.String("user-agent", c.Request.UserAgent()),
- zap.String("errors", c.Errors.ByType(gin.ErrorTypePrivate).String()),
- zap.Duration("cost", cost),
- )
- }
|