diff --git a/api_gorm.go b/api_gorm.go index 6a838f0..508d8b5 100644 --- a/api_gorm.go +++ b/api_gorm.go @@ -6,7 +6,6 @@ import ( "go.dtapp.net/gorequest" "gorm.io/datatypes" "gorm.io/gorm" - "log" "time" "unicode/utf8" ) @@ -29,13 +28,13 @@ type apiPostgresqlLog struct { SystemHostName string `gorm:"index;comment:【系统】主机名" json:"system_host_name,omitempty"` //【系统】主机名 SystemInsideIp string `gorm:"index;comment:【系统】内网ip" json:"system_inside_ip,omitempty"` //【系统】内网ip GoVersion string `gorm:"index;comment:【程序】Go版本" json:"go_version,omitempty"` //【程序】Go版本 + SdkVersion string `gorm:"index;comment:【程序】Sdk版本" json:"sdk_version,omitempty"` //【程序】Sdk版本 } // 记录日志 func (c *ApiClient) gormRecord(postgresqlLog apiPostgresqlLog) error { if utf8.ValidString(string(postgresqlLog.ResponseBody)) == false { - log.Println("内容格式无法记录") postgresqlLog.ResponseBody = datatypes.JSON("") } @@ -54,9 +53,8 @@ func (c *ApiClient) GormQuery() *gorm.DB { } // GormMiddleware 中间件 -func (c *ApiClient) GormMiddleware(request gorequest.Response) { +func (c *ApiClient) GormMiddleware(request gorequest.Response, sdkVersion string) { if request.ResponseHeader.Get("Content-Type") == "image/jpeg" || request.ResponseHeader.Get("Content-Type") == "image/png" { - log.Println("内容格式无法记录") return } c.gormRecord(apiPostgresqlLog{ @@ -72,11 +70,12 @@ func (c *ApiClient) GormMiddleware(request gorequest.Response) { ResponseBody: request.ResponseBody, //【返回】内容 ResponseContentLength: request.ResponseContentLength, //【返回】大小 ResponseTime: request.ResponseTime, //【返回】时间 + SdkVersion: sdkVersion, //【程序】Sdk版本 }) } // GormMiddlewareXml 中间件 -func (c *ApiClient) GormMiddlewareXml(request gorequest.Response) { +func (c *ApiClient) GormMiddlewareXml(request gorequest.Response, sdkVersion string) { c.gormRecord(apiPostgresqlLog{ RequestTime: request.RequestTime, //【请求】时间 RequestUri: request.RequestUri, //【请求】链接 @@ -90,11 +89,12 @@ func (c *ApiClient) GormMiddlewareXml(request gorequest.Response) { ResponseBody: datatypes.JSON(gojson.JsonEncodeNoError(dorm.XmlDecodeNoError(request.ResponseBody))), //【返回】内容 ResponseContentLength: request.ResponseContentLength, //【返回】大小 ResponseTime: request.ResponseTime, //【返回】时间 + SdkVersion: sdkVersion, //【程序】Sdk版本 }) } // GormMiddlewareCustom 中间件 -func (c *ApiClient) GormMiddlewareCustom(api string, request gorequest.Response) { +func (c *ApiClient) GormMiddlewareCustom(api string, request gorequest.Response, sdkVersion string) { c.gormRecord(apiPostgresqlLog{ RequestTime: request.RequestTime, //【请求】时间 RequestUri: request.RequestUri, //【请求】链接 @@ -108,5 +108,6 @@ func (c *ApiClient) GormMiddlewareCustom(api string, request gorequest.Response) ResponseBody: request.ResponseBody, //【返回】内容 ResponseContentLength: request.ResponseContentLength, //【返回】大小 ResponseTime: request.ResponseTime, //【返回】时间 + SdkVersion: sdkVersion, //【程序】Sdk版本 }) } diff --git a/const.go b/const.go index cbe7087..b12e74f 100644 --- a/const.go +++ b/const.go @@ -1,3 +1,3 @@ package golog -const Version = "1.0.20" +const Version = "1.0.21" diff --git a/gin_gorm.go b/gin_gorm.go index 5826432..19e667e 100644 --- a/gin_gorm.go +++ b/gin_gorm.go @@ -39,11 +39,12 @@ type ginPostgresqlLog struct { ResponseTime time.Time `gorm:"index;comment:【返回】时间" json:"response_time,omitempty"` //【返回】时间 ResponseCode int `gorm:"index;comment:【返回】状态码" json:"response_code,omitempty"` //【返回】状态码 ResponseMsg string `gorm:"comment:【返回】描述" json:"response_msg,omitempty"` //【返回】描述 - ResponseData datatypes.JSON `gorm:"type:jsonb;comment:/【返回】数据" json:"response_data,omitempty"` //【返回】数据 + ResponseData datatypes.JSON `gorm:"type:jsonb;comment:【返回】数据" json:"response_data,omitempty"` //【返回】数据 CostTime int64 `gorm:"comment:【系统】花费时间" json:"cost_time,omitempty"` //【系统】花费时间 SystemHostName string `gorm:"index;comment:【系统】主机名" json:"system_host_name,omitempty"` //【系统】主机名 SystemInsideIp string `gorm:"index;comment:【系统】内网ip" json:"system_inside_ip,omitempty"` //【系统】内网ip GoVersion string `gorm:"index;comment:【程序】Go版本" json:"go_version,omitempty"` //【程序】Go版本 + SdkVersion string `gorm:"index;comment:【程序】Sdk版本" json:"sdk_version,omitempty"` //【程序】Sdk版本 } // gormRecord 记录日志 @@ -54,6 +55,7 @@ func (c *GinClient) gormRecord(postgresqlLog ginPostgresqlLog) error { postgresqlLog.SystemInsideIp = c.config.insideIp } postgresqlLog.GoVersion = c.config.goVersion + postgresqlLog.SdkVersion = Version return c.gormClient.Table(c.config.tableName).Create(&postgresqlLog).Error }