refactor🎨: 调整客户端ip获取方法以及日志中对应位置更新
This commit is contained in:
1 parent
ed52efaa44
commit
e0cf7af7a9
4 files changed
+28
-10
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"go-admin/common"
|
||||
gaConfig "go-admin/config"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
@@ -80,12 +81,7 @@ func LoggerToFile() gin.HandlerFunc {
|
||||
// 状态码
|
||||
statusCode := c.Writer.Status()
|
||||
// 请求IP
|
||||
clientIP := c.ClientIP()
|
||||
|
||||
|
||||
fmt.Println("Headers:", c.Request.Header.Get("X-Real-IP"))
|
||||
|
||||
fmt.Println("clientIP:", clientIP)
|
||||
clientIP := common.GetClientIP(c)
|
||||
// 执行时间
|
||||
latencyTime := endTime.Sub(startTime)
|
||||
// 日志格式
|
||||
@@ -111,6 +107,7 @@ func SetDBOperLog(c *gin.Context, clientIP string, statusCode int, reqUri string
|
||||
l["_fullPath"] = c.FullPath()
|
||||
l["operUrl"] = reqUri
|
||||
l["operIp"] = clientIP
|
||||
fmt.Println("gaConfig.ExtConfig.AMap.Key", gaConfig.ExtConfig.AMap.Key)
|
||||
l["operLocation"] = pkg.GetLocation(clientIP, gaConfig.ExtConfig.AMap.Key)
|
||||
l["operName"] = user.GetUserName(c)
|
||||
l["requestMethod"] = c.Request.Method
|
||||
@@ -135,4 +132,4 @@ func SetDBOperLog(c *gin.Context, clientIP string, statusCode int, reqUri string
|
||||
log.Errorf("Append message error, %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user