附近小店
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

32 行
665 B

  1. package mw
  2. import (
  3. "time"
  4. "github.com/gin-gonic/gin"
  5. "go.uber.org/zap"
  6. "applet/app/utils/logx"
  7. )
  8. // access log
  9. func AccessLog(c *gin.Context) {
  10. start := time.Now()
  11. c.Next()
  12. cost := time.Since(start)
  13. logx.Info(c.Request.URL.Path)
  14. logger := &zap.Logger{}
  15. logger.Info(c.Request.URL.Path,
  16. zap.Int("status", c.Writer.Status()),
  17. zap.String("method", c.Request.Method),
  18. zap.String("path", c.Request.URL.Path),
  19. zap.String("query", c.Request.URL.RawQuery),
  20. zap.String("ip", c.ClientIP()),
  21. zap.String("user-agent", c.Request.UserAgent()),
  22. zap.String("errors", c.Errors.ByType(gin.ErrorTypePrivate).String()),
  23. zap.Duration("cost", cost),
  24. )
  25. }