智盟项目
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
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. }