低空智控平台 后端go
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.
 
 

25 lines
477 B

package middleware
import (
"time"
"github.com/gin-gonic/gin"
"laic-backend/logger"
)
// DefaultLogMiddleware 访问日志:方法、路径、状态码、耗时、来源 IP
func DefaultLogMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
start := time.Now()
c.Next()
latency := time.Since(start)
logger.INFO(
c.Request.Method,
c.Request.URL.Path,
"status", c.Writer.Status(),
"ip", c.ClientIP(),
"latency", latency.String(),
)
}
}