- update log

master
李光春 2 years ago
parent ec312764d8
commit a8db9e83da

1
.gitignore vendored

@ -8,3 +8,4 @@
*_test.go
/service/*_test.go
/utils/*_test.go
*.text

@ -6,7 +6,7 @@ require (
gitee.com/chunanyong/zorm v1.5.5
github.com/aliyun/aliyun-oss-go-sdk v2.2.4+incompatible
github.com/allegro/bigcache/v3 v3.0.2
github.com/aws/aws-sdk-go v1.44.37
github.com/aws/aws-sdk-go v1.44.38
github.com/baidubce/bce-sdk-go v0.9.124
github.com/basgys/goxml2json v1.1.0
github.com/beego/beego/v2 v2.0.4

@ -39,8 +39,8 @@ github.com/aws/aws-lambda-go v1.13.3/go.mod h1:4UKl9IzQMoD+QF79YdCuzCwp8VbmG4VAQ
github.com/aws/aws-sdk-go v1.25.3/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.27.0/go.mod h1:KmX6BPdI08NWTb3/sm4ZGu5ShLoqVDhKgpiN924inxo=
github.com/aws/aws-sdk-go v1.42.27/go.mod h1:OGr6lGMAKGlG9CVrYnWYDKIyb829c6EVBRjxqjmPepc=
github.com/aws/aws-sdk-go v1.44.37 h1:KvDxCX6dfJeEDC77U5GPGSP0ErecmNnhDHFxw+NIvlI=
github.com/aws/aws-sdk-go v1.44.37/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/aws/aws-sdk-go v1.44.38 h1:Mjsc6XXoAA1QHDqDZQ7vOWd+fUmM29coG+AzkSWmRxI=
github.com/aws/aws-sdk-go v1.44.38/go.mod h1:y4AeaBuwd2Lk+GepC1E9v0qOiTws0MIWAX4oIKwKHZo=
github.com/aws/aws-sdk-go-v2 v0.18.0/go.mod h1:JWVYvqSMppoMJC0x5wdwiImzgXTI9FuZwxzkQq9wy+g=
github.com/baidubce/bce-sdk-go v0.9.124 h1:wQrZ+BbtMAj7MOOHkaltW8Zp4M3KhHL1N38PjC1lWT8=
github.com/baidubce/bce-sdk-go v0.9.124/go.mod h1:zbYJMQwE4IZuyrJiFO8tO8NbtYiKTFTbwh4eIsqjVdg=

@ -3,9 +3,9 @@ package golog
import (
"context"
"errors"
"github.com/siddontang/go/bson"
"go.dtapp.net/library/utils/dorm"
"go.dtapp.net/library/utils/goip"
"go.mongodb.org/mongo-driver/bson/primitive"
"gorm.io/datatypes"
"gorm.io/gorm"
"log"
@ -19,7 +19,7 @@ import (
type ApiClient struct {
gormClient *gorm.DB // 驱动
mongoCollectionClient *dorm.MongoClient // 驱动(温馨提示:需要已选择库)
config *struct {
config struct {
logType string // 日志类型
tableName string // 表名
insideIp string // 内网ip
@ -29,10 +29,13 @@ type ApiClient struct {
}
// NewApiClient 创建接口实例化
// WithGormClient && WithTableName
// WithMongoCollectionClient && WithTableName
func NewApiClient(attrs ...*OperationAttr) (*ApiClient, error) {
c := &ApiClient{}
for _, attr := range attrs {
log.Println(attr)
c.gormClient = attr.gormClient
c.mongoCollectionClient = attr.mongoCollectionClient
c.config.logType = attr.logType
@ -111,7 +114,7 @@ func (c *ApiClient) MongoRecord(mongoLog ApiMongoLog) error {
}
mongoLog.GoVersion = c.config.goVersion
mongoLog.LogId = bson.NewObjectId()
mongoLog.LogId = primitive.NewObjectID()
_, err := c.mongoCollectionClient.InsertOne(context.Background(), mongoLog)
return err

@ -4,7 +4,7 @@ import "gorm.io/datatypes"
// ApiPostgresqlLog 结构体
type ApiPostgresqlLog struct {
LogId uint `gorm:"primaryKey" json:"log_id"` //【记录】编号
LogId uint `gorm:"primaryKey" json:"log_id,omitempty"` //【记录】编号
RequestTime TimeString `gorm:"index" json:"request_time,omitempty"` //【请求】时间
RequestUri string `gorm:"type:text" json:"request_uri,omitempty"` //【请求】链接
RequestUrl string `gorm:"type:text" json:"request_url,omitempty"` //【请求】链接

@ -1,13 +1,13 @@
package golog
import (
"github.com/siddontang/go/bson"
"go.dtapp.net/library/utils/dorm"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// ApiMongoLog 结构体
type ApiMongoLog struct {
LogId bson.ObjectId `json:"log_id" bson:"log_id"` //【记录】编号
LogId primitive.ObjectID `json:"log_id,omitempty" bson:"_id,omitempty"` //【记录】编号
RequestTime dorm.BsonTime `json:"request_time,omitempty" bson:"request_time,omitempty"` //【请求】时间
RequestUri string `json:"request_uri,omitempty" bson:"request_uri,omitempty"` //【请求】链接
RequestUrl string `json:"request_url,omitempty" bson:"request_url,omitempty"` //【请求】链接

@ -3,9 +3,9 @@ package golog
import (
"context"
"errors"
"github.com/siddontang/go/bson"
"go.dtapp.net/library/utils/dorm"
"go.dtapp.net/library/utils/goip"
"go.mongodb.org/mongo-driver/bson/primitive"
"gorm.io/gorm"
"os"
"runtime"
@ -16,7 +16,7 @@ import (
type GinClient struct {
gormClient *gorm.DB // 驱动
mongoCollectionClient *dorm.MongoClient // 驱动(温馨提示:需要已选择库)
config *struct {
config struct {
logType string // 日志类型
tableName string // 表名
insideIp string // 内网ip
@ -103,7 +103,7 @@ func (c *GinClient) MongoRecord(mongoLog GinMongoLog) error {
}
mongoLog.GoVersion = c.config.goVersion
mongoLog.LogId = bson.NewObjectId()
mongoLog.LogId = primitive.NewObjectID()
_, err := c.mongoCollectionClient.InsertOne(context.Background(), mongoLog)
return err

@ -4,7 +4,7 @@ import "gorm.io/datatypes"
// GinPostgresqlLog 结构体
type GinPostgresqlLog struct {
LogId uint `gorm:"primaryKey" json:"log_id"` //【记录】编号
LogId uint `gorm:"primaryKey" json:"log_id,omitempty"` //【记录】编号
TraceId string `gorm:"type:text" json:"trace_id,omitempty"` //【系统】链编号
RequestTime TimeString `gorm:"index" json:"request_time,omitempty"` //【请求】时间
RequestUri string `gorm:"type:text" json:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数

@ -1,37 +1,37 @@
package golog
import (
"github.com/siddontang/go/bson"
"go.dtapp.net/library/utils/dorm"
"go.mongodb.org/mongo-driver/bson/primitive"
)
// GinMongoLog 结构体
type GinMongoLog struct {
LogId bson.ObjectId `json:"log_id" bson:"log_id"` //【记录】编号
TraceId string `json:"trace_id,omitempty" bson:"trace_id,omitempty"` //【系统】链编号
RequestTime dorm.BsonTime `json:"request_time,omitempty" bson:"request_time,omitempty"` //【请求】时间
RequestUri string `json:"request_uri,omitempty" bson:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
RequestUrl string `json:"request_url,omitempty" bson:"request_url,omitempty"` //【请求】请求链接 域名+路径
RequestApi string `json:"request_api,omitempty" bson:"request_api,omitempty"` //【请求】请求接口 路径
RequestMethod string `json:"request_method,omitempty" bson:"request_method,omitempty"` //【请求】请求方式
RequestProto string `json:"request_proto,omitempty" bson:"request_proto,omitempty"` //【请求】请求协议
RequestUa string `json:"request_ua,omitempty" bson:"request_ua,omitempty"` //【请求】请求UA
RequestReferer string `json:"request_referer,omitempty" bson:"request_referer,omitempty"` //【请求】请求referer
RequestBody interface{} `json:"request_body,omitempty" bson:"request_body,omitempty"` //【请求】请求主体
RequestUrlQuery interface{} `json:"request_url_query,omitempty" bson:"request_url_query,omitempty"` //【请求】请求URL参数
RequestIp string `json:"request_ip,omitempty" bson:"request_ip,omitempty"` //【请求】请求客户端Ip
RequestIpCountry string `json:"request_ip_country,omitempty" bson:"request_ip_country,omitempty"` //【请求】请求客户端城市
RequestIpRegion string `json:"request_ip_region,omitempty" bson:"request_ip_region,omitempty"` //【请求】请求客户端区域
RequestIpProvince string `json:"request_ip_province,omitempty" bson:"request_ip_province,omitempty"` //【请求】请求客户端省份
RequestIpCity string `json:"request_ip_city,omitempty" bson:"request_ip_city,omitempty"` //【请求】请求客户端城市
RequestIpIsp string `json:"request_ip_isp,omitempty" bson:"request_ip_isp,omitempty"` //【请求】请求客户端运营商
RequestHeader interface{} `json:"request_header,omitempty" bson:"request_header,omitempty"` //【请求】请求头
ResponseTime dorm.BsonTime `json:"response_time,omitempty" bson:"response_time,omitempty"` //【返回】时间
ResponseCode int `json:"response_code,omitempty" bson:"response_code,omitempty"` //【返回】状态码
ResponseMsg string `json:"response_msg,omitempty" bson:"response_msg,omitempty"` //【返回】描述
ResponseData interface{} `json:"response_data,omitempty" bson:"response_data,omitempty"` //【返回】数据
CostTime int64 `json:"cost_time,omitempty" bson:"cost_time,omitempty"` //【系统】花费时间
SystemHostName string `json:"system_host_name,omitempty" bson:"system_host_name,omitempty"` //【系统】主机名
SystemInsideIp string `json:"system_inside_ip,omitempty" bson:"system_inside_ip,omitempty"` //【系统】内网ip
GoVersion string `json:"go_version,omitempty" bson:"go_version,omitempty"` //【程序】Go版本
LogId primitive.ObjectID `json:"log_id,omitempty" bson:"_id,omitempty"` //【记录】编号
TraceId string `json:"trace_id,omitempty" bson:"trace_id,omitempty"` //【系统】链编号
RequestTime dorm.BsonTime `json:"request_time,omitempty" bson:"request_time,omitempty"` //【请求】时间
RequestUri string `json:"request_uri,omitempty" bson:"request_uri,omitempty"` //【请求】请求链接 域名+路径+参数
RequestUrl string `json:"request_url,omitempty" bson:"request_url,omitempty"` //【请求】请求链接 域名+路径
RequestApi string `json:"request_api,omitempty" bson:"request_api,omitempty"` //【请求】请求接口 路径
RequestMethod string `json:"request_method,omitempty" bson:"request_method,omitempty"` //【请求】请求方式
RequestProto string `json:"request_proto,omitempty" bson:"request_proto,omitempty"` //【请求】请求协议
RequestUa string `json:"request_ua,omitempty" bson:"request_ua,omitempty"` //【请求】请求UA
RequestReferer string `json:"request_referer,omitempty" bson:"request_referer,omitempty"` //【请求】请求referer
RequestBody interface{} `json:"request_body,omitempty" bson:"request_body,omitempty"` //【请求】请求主体
RequestUrlQuery interface{} `json:"request_url_query,omitempty" bson:"request_url_query,omitempty"` //【请求】请求URL参数
RequestIp string `json:"request_ip,omitempty" bson:"request_ip,omitempty"` //【请求】请求客户端Ip
RequestIpCountry string `json:"request_ip_country,omitempty" bson:"request_ip_country,omitempty"` //【请求】请求客户端城市
RequestIpRegion string `json:"request_ip_region,omitempty" bson:"request_ip_region,omitempty"` //【请求】请求客户端区域
RequestIpProvince string `json:"request_ip_province,omitempty" bson:"request_ip_province,omitempty"` //【请求】请求客户端省份
RequestIpCity string `json:"request_ip_city,omitempty" bson:"request_ip_city,omitempty"` //【请求】请求客户端城市
RequestIpIsp string `json:"request_ip_isp,omitempty" bson:"request_ip_isp,omitempty"` //【请求】请求客户端运营商
RequestHeader interface{} `json:"request_header,omitempty" bson:"request_header,omitempty"` //【请求】请求头
ResponseTime dorm.BsonTime `json:"response_time,omitempty" bson:"response_time,omitempty"` //【返回】时间
ResponseCode int `json:"response_code,omitempty" bson:"response_code,omitempty"` //【返回】状态码
ResponseMsg string `json:"response_msg,omitempty" bson:"response_msg,omitempty"` //【返回】描述
ResponseData interface{} `json:"response_data,omitempty" bson:"response_data,omitempty"` //【返回】数据
CostTime int64 `json:"cost_time,omitempty" bson:"cost_time,omitempty"` //【系统】花费时间
SystemHostName string `json:"system_host_name,omitempty" bson:"system_host_name,omitempty"` //【系统】主机名
SystemInsideIp string `json:"system_inside_ip,omitempty" bson:"system_inside_ip,omitempty"` //【系统】内网ip
GoVersion string `json:"go_version,omitempty" bson:"go_version,omitempty"` //【程序】Go版本
}

Loading…
Cancel
Save