- update gorm

master v1.0.58
李光春 2 years ago
parent f14ff39dde
commit 7e275ff8c6

@ -74,25 +74,25 @@ func (c *ApiClient) gormAutoMigrate() (err error) {
// 模型结构体
type apiPostgresqlLog struct {
LogId uint `gorm:"primaryKey;comment:【记录】编号" json:"log_id,omitempty"` //【记录】编号
TraceId string `gorm:"index;comment:【系统】跟踪编号" json:"trace_id,omitempty"` //【系统】跟踪编号
RequestTime time.Time `gorm:"index;comment:【请求】时间" json:"request_time,omitempty"` //【请求】时间
RequestUri string `gorm:"comment:【请求】链接" json:"request_uri,omitempty"` //【请求】链接
RequestUrl string `gorm:"comment:【请求】链接" json:"request_url,omitempty"` //【请求】链接
RequestApi string `gorm:"index;comment:【请求】接口" json:"request_api,omitempty"` //【请求】接口
RequestMethod string `gorm:"index;comment:【请求】方式" json:"request_method,omitempty"` //【请求】方式
RequestParams datatypes.JSON `gorm:"type:jsonb;comment:【请求】参数" json:"request_params,omitempty"` //【请求】参数
RequestHeader datatypes.JSON `gorm:"type:jsonb;comment:【请求】头部" json:"request_header,omitempty"` //【请求】头部
ResponseHeader datatypes.JSON `gorm:"type:jsonb;comment:【返回】头部" json:"response_header,omitempty"` //【返回】头部
ResponseStatusCode int `gorm:"index;comment:【返回】状态码" json:"response_status_code,omitempty"` //【返回】状态码
ResponseBody datatypes.JSON `gorm:"type:jsonb;comment:【返回】内容" json:"response_body,omitempty"` //【返回】内容
ResponseBodyXml string `gorm:"type:xml;comment:【返回】内容 Xml格式" json:"response_body_xml,omitempty"` //【返回】内容 Xml格式
ResponseContentLength int64 `gorm:"comment:【返回】大小" json:"response_content_length,omitempty"` //【返回】大小
ResponseTime time.Time `gorm:"index;comment:【返回】时间" json:"response_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版本
LogId uint `gorm:"primaryKey;comment:【记录】编号" json:"log_id,omitempty"` //【记录】编号
TraceId string `gorm:"index;comment:【系统】跟踪编号" json:"trace_id,omitempty"` //【系统】跟踪编号
RequestTime time.Time `gorm:"index;comment:【请求】时间" json:"request_time,omitempty"` //【请求】时间
RequestUri string `gorm:"comment:【请求】链接" json:"request_uri,omitempty"` //【请求】链接
RequestUrl string `gorm:"comment:【请求】链接" json:"request_url,omitempty"` //【请求】链接
RequestApi string `gorm:"index;comment:【请求】接口" json:"request_api,omitempty"` //【请求】接口
RequestMethod string `gorm:"index;comment:【请求】方式" json:"request_method,omitempty"` //【请求】方式
RequestParams datatypes.JSON `gorm:"type:jsonb;comment:【请求】参数" json:"request_params,omitempty"` //【请求】参数
RequestHeader datatypes.JSON `gorm:"type:jsonb;comment:【请求】头部" json:"request_header,omitempty"` //【请求】头部
ResponseHeader datatypes.JSON `gorm:"type:jsonb;comment:【返回】头部" json:"response_header,omitempty"` //【返回】头部
ResponseStatusCode int `gorm:"index;comment:【返回】状态码" json:"response_status_code,omitempty"` //【返回】状态码
ResponseBody datatypes.JSON `gorm:"type:jsonb;comment:【返回】数据" json:"response_body,omitempty"` //【返回】数据
ResponseContent string `gorm:"comment:【返回】内容" json:"response_content,omitempty"` //【返回】内容
ResponseContentLength int64 `gorm:"comment:【返回】大小" json:"response_content_length,omitempty"` //【返回】大小
ResponseTime time.Time `gorm:"index;comment:【返回】时间" json:"response_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版本
}
// 记录日志
@ -137,8 +137,9 @@ func (c *ApiClient) GormMiddleware(ctx context.Context, request gorequest.Respon
if request.HeaderIsImg() {
c.zapLog.WithTraceId(ctx).Sugar().Infof("[log.GormMiddleware]%s %s\n", data.RequestUri, request.ResponseHeader.Get("Content-Type"))
} else {
if len(dorm.JsonDecodeNoError(request.ResponseBody)) > 0 {
data.ResponseBody = request.ResponseBody //【返回】内容
if len(dorm.JsonEncodeNoError(request.ResponseBody)) > 0 {
data.ResponseBody = request.ResponseBody //【返回】数据
data.ResponseContent = dorm.JsonEncodeNoError(request.ResponseBody) //【返回】数据
} else {
c.zapLog.WithTraceId(ctx).Sugar().Infof("[log.GormMiddleware]%s %s\n", data.RequestUri, request.ResponseBody)
}
@ -169,7 +170,7 @@ func (c *ApiClient) GormMiddlewareXml(ctx context.Context, request gorequest.Res
c.zapLog.WithTraceId(ctx).Sugar().Infof("[log.GormMiddlewareXml]%s %s\n", data.RequestUri, request.ResponseHeader.Get("Content-Type"))
} else {
if len(string(request.ResponseBody)) > 0 {
data.ResponseBodyXml = string(request.ResponseBody) //【返回】内容 Xml格式
data.ResponseContent = string(request.ResponseBody) //【返回】内容
} else {
c.zapLog.WithTraceId(ctx).Sugar().Infof("[log.GormMiddlewareXml]%s %s\n", data.RequestUri, request.ResponseBody)
}
@ -199,8 +200,9 @@ func (c *ApiClient) GormMiddlewareCustom(ctx context.Context, api string, reques
if request.HeaderIsImg() {
c.zapLog.WithTraceId(ctx).Sugar().Infof("[log.GormMiddlewareCustom]%s %s\n", data.RequestUri, request.ResponseHeader.Get("Content-Type"))
} else {
if len(dorm.JsonDecodeNoError(request.ResponseBody)) > 0 {
data.ResponseBody = request.ResponseBody //【返回】内容
if len(dorm.JsonEncodeNoError(request.ResponseBody)) > 0 {
data.ResponseBody = request.ResponseBody //【返回】数据
data.ResponseContent = dorm.JsonEncodeNoError(request.ResponseBody) //【返回】数据
} else {
c.zapLog.WithTraceId(ctx).Sugar().Infof("[log.GormMiddlewareCustom]%s %s\n", data.RequestUri, request.ResponseBody)
}

@ -1,5 +1,5 @@
package golog
const (
Version = "1.0.57"
Version = "1.0.58"
)

@ -95,7 +95,7 @@ type ginPostgresqlLog struct {
RequestUa string `gorm:"comment:【请求】请求UA" json:"request_ua,omitempty"` //【请求】请求UA
RequestReferer string `gorm:"comment:【请求】请求referer" json:"request_referer,omitempty"` //【请求】请求referer
RequestBody datatypes.JSON `gorm:"type:jsonb;comment:【请求】请求主体" json:"request_body,omitempty"` //【请求】请求主体
RequestBodyXml string `gorm:"type:xml;comment:【请求】请求主体 Xml格式" json:"request_body_xml,omitempty"` //【请求】请求主体 Xml格式
RequestContent string `gorm:"comment:【请求】请求内容" json:"request_content,omitempty"` //【请求】请求内容
RequestUrlQuery datatypes.JSON `gorm:"type:jsonb;comment:【请求】请求URL参数" json:"request_url_query,omitempty"` //【请求】请求URL参数
RequestIp string `gorm:"index;comment:【请求】请求客户端Ip" json:"request_ip,omitempty"` //【请求】请求客户端Ip
RequestIpCountry string `gorm:"index;comment:【请求】请求客户端城市" json:"request_ip_country,omitempty"` //【请求】请求客户端城市
@ -108,6 +108,7 @@ type ginPostgresqlLog struct {
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"` //【返回】数据
ResponseContent string `gorm:"comment:【返回】内容" json:"response_content,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
@ -150,6 +151,7 @@ func (c *GinClient) gormRecordJson(ginCtx *gin.Context, traceId string, requestT
ResponseTime: gotime.Current().Time, //【返回】时间
ResponseCode: responseCode, //【返回】状态码
ResponseData: datatypes.JSON(responseBody), //【返回】数据
ResponseContent: dorm.JsonEncodeNoError(responseBody), //【返回】内容
CostTime: endTime - startTime, //【系统】花费时间
}
if ginCtx.Request.TLS == nil {
@ -160,6 +162,7 @@ func (c *GinClient) gormRecordJson(ginCtx *gin.Context, traceId string, requestT
if len(dorm.JsonEncodeNoError(requestBody)) > 0 {
data.RequestBody = datatypes.JSON(dorm.JsonEncodeNoError(requestBody)) //【请求】请求主体
data.RequestContent = dorm.JsonEncodeNoError(requestBody) //【请求】请求内容
} else {
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[log.gormRecordJson]%s %s\n", data.RequestUri, requestBody)
}
@ -191,6 +194,7 @@ func (c *GinClient) gormRecordXml(ginCtx *gin.Context, traceId string, requestTi
ResponseTime: gotime.Current().Time, //【返回】时间
ResponseCode: responseCode, //【返回】状态码
ResponseData: datatypes.JSON(responseBody), //【返回】数据
ResponseContent: dorm.JsonEncodeNoError(responseBody), //【返回】内容
CostTime: endTime - startTime, //【系统】花费时间
}
if ginCtx.Request.TLS == nil {
@ -200,7 +204,7 @@ func (c *GinClient) gormRecordXml(ginCtx *gin.Context, traceId string, requestTi
}
if len(requestBody) > 0 {
data.RequestBodyXml = requestBody //【请求】请求主体 Xml格式
data.RequestContent = requestBody //【请求】请求内容
} else {
c.zapLog.WithTraceIdStr(traceId).Sugar().Infof("[log.gormRecordXml]%s %s\n", data.RequestUri, requestBody)
}

Loading…
Cancel
Save