Commit 1dadd8a3 by 杨树贤

完善日志格式

parent 40b95f7b
package app package http
import ( import (
"LC_soapi/pkg/logging"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
...@@ -15,10 +16,15 @@ type Response struct { ...@@ -15,10 +16,15 @@ type Response struct {
} }
// Response setting gin.JSON // Response setting gin.JSON
func (g *Gin) Response(errCode int, errMsg string, data interface{}) { func (g *Gin) Response(code int, msg string, data interface{}) {
if code > 100 {
logging.ReportErrorLog(code, msg, g.C.ClientIP())
}
g.C.JSON(200, Response{ g.C.JSON(200, Response{
Code: errCode, Code: code,
Msg: errMsg, Msg: msg,
Data: data, Data: data,
}) })
return return
......
...@@ -22,7 +22,7 @@ type ErrorLog struct { ...@@ -22,7 +22,7 @@ type ErrorLog struct {
} }
//上报请求日志 //上报请求日志
func ReportErrorLog(msg string, code int, method string,ip string) { func ReportErrorLog(code int, msg string, ip string) {
var errLog ErrorLog var errLog ErrorLog
//获取调用者信息 //获取调用者信息
caller := util.GetCaller(2) caller := util.GetCaller(2)
...@@ -32,7 +32,7 @@ func ReportErrorLog(msg string, code int, method string,ip string) { ...@@ -32,7 +32,7 @@ func ReportErrorLog(msg string, code int, method string,ip string) {
errLog.App = setting.AppSetting.Name errLog.App = setting.AppSetting.Name
errLog.ServerIp = ip errLog.ServerIp = ip
errLog.Method = "g.G.Routes()" errLog.Method = caller.FunctionName
errLog.FileName = caller.FileName errLog.FileName = caller.FileName
errLog.LineNo = caller.FileLine errLog.LineNo = caller.FileLine
logString, _ := json.Marshal(errLog) logString, _ := json.Marshal(errLog)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment