提交
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func LoggerFormat() gin.HandlerFunc {
|
||||
|
||||
return gin.LoggerWithFormatter(func(param gin.LogFormatterParams) string {
|
||||
|
||||
// 你的自定义格式
|
||||
return fmt.Sprintf("[VISIT] UUID:%s | IP:%s | 时间:%s | 方法:%s | 路径:%s | 协议:%s | 状态码:%d | 耗时:%s | 代理头:%s | 错误信息:%s \n",
|
||||
// UUID
|
||||
param.Keys["uuid"],
|
||||
//客户端IP
|
||||
param.ClientIP,
|
||||
//时间格式
|
||||
param.TimeStamp.Format("2006-01-02 15:04:05"),
|
||||
//http请求方式 get post等
|
||||
param.Method,
|
||||
//客户端请求的路径
|
||||
param.Path,
|
||||
//http请求协议版本
|
||||
param.Request.Proto,
|
||||
//http请求状态码
|
||||
param.StatusCode,
|
||||
//请求耗时
|
||||
param.Latency,
|
||||
//http请求代理头
|
||||
param.Request.UserAgent(),
|
||||
//处理请求错误时设置错误消息
|
||||
param.ErrorMessage,
|
||||
)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user