附近小店
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

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