| 1234567891011121314151617181920212223242526 |
- package middleware
- import (
- "app/commons/core"
- "github.com/gin-gonic/gin"
- "time"
- )
- // 自定义日志拦截
- func GinLogger() gin.HandlerFunc {
- return func(c *gin.Context) {
- start := time.Now()
- defer func() {
- // 在请求结束时记录日志
- elapsed := time.Since(start)
- core.Log.Infof("GIN|%d|%s|IP:%s|%s|URI:%s|",
- c.Writer.Status(),
- elapsed.Round(time.Millisecond),
- c.ClientIP(),
- c.Request.Method,
- c.Request.URL.Path)
- }()
- c.Next()
- }
- }
|