广告平台(站长下代理使用)
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mw_access_log.go 665 B

2 달 전
12345678910111213141516171819202122232425262728293031
  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. }