- update gin_slog

master
dtapps 4 months ago
parent 0b68d2d075
commit d63a3e16d1

@ -1,38 +0,0 @@
package golog
import "go.dtapp.net/goip"
// GinClient 框架日志
type GinClient struct {
ipService *goip.Client // IP服务
slog struct {
status bool // 状态
client *SLog // 日志服务
}
}
// GinClientFun 框架日志驱动
type GinClientFun func() *GinClient
// GinClientConfig 框架日志配置
type GinClientConfig struct {
IpService *goip.Client // IP服务
}
// GinCustomClient 框架自定义日志
type GinCustomClient struct {
ipService *goip.Client // IP服务
slog struct {
status bool // 状态
client *SLog // 日志服务
}
}
// GinCustomClientFun 框架自定义日志驱动
type GinCustomClientFun func() *GinCustomClient
// GinCustomClientConfig 框架自定义日志配置
type GinCustomClientConfig struct {
IpService *goip.Client // IP服务
CurrentIp string // 当前IP
}

@ -1,11 +0,0 @@
package golog
import (
"context"
)
func NewGinCustomClient(ctx context.Context, config *GinCustomClientConfig) (*GinCustomClient, error) {
c := &GinCustomClient{}
c.ipService = config.IpService
return c, nil
}

@ -12,10 +12,22 @@ import (
"io/ioutil"
)
// NewGinClient 创建框架实例化
func NewGinClient(ctx context.Context, config *GinClientConfig) (*GinClient, error) {
c := &GinClient{}
c.ipService = config.IpService
// GinSLog 框架日志
type GinSLog struct {
ipService *goip.Client // IP服务
slog struct {
status bool // 状态
client *SLog // 日志服务
}
}
// GinSLogFun 框架日志驱动
type GinSLogFun func() *GinSLog
// NewGinSLog 创建框架实例化
func NewGinSLog(ctx context.Context, ipService *goip.Client) (*GinSLog, error) {
c := &GinSLog{}
c.ipService = ipService
return c, nil
}
@ -34,13 +46,13 @@ func (w bodyLogWriter) WriteString(s string) (int, error) {
return w.ResponseWriter.WriteString(s)
}
func (c *GinClient) jsonUnmarshal(data string) (result interface{}) {
func (c *GinSLog) jsonUnmarshal(data string) (result interface{}) {
_ = gojson.Unmarshal([]byte(data), &result)
return
}
// Middleware 中间件
func (c *GinClient) Middleware() gin.HandlerFunc {
func (c *GinSLog) Middleware() gin.HandlerFunc {
return func(ginCtx *gin.Context) {
// 开始时间

@ -1,7 +1,7 @@
package golog
// ConfigSLogClientFun 日志配置
func (c *GinClient) ConfigSLogClientFun(sLogFun SLogFun) {
func (c *GinSLog) ConfigSLogClientFun(sLogFun SLogFun) {
sLog := sLogFun()
if sLog != nil {
c.slog.client = sLog
@ -10,7 +10,7 @@ func (c *GinClient) ConfigSLogClientFun(sLogFun SLogFun) {
}
// ConfigSLogResultClientFun 日志配置然后返回
func (c *GinClient) ConfigSLogResultClientFun(sLogFun SLogFun) *GinClient {
func (c *GinSLog) ConfigSLogResultClientFun(sLogFun SLogFun) *GinSLog {
sLog := sLogFun()
if sLog != nil {
c.slog.client = sLog

@ -0,0 +1,25 @@
package golog
import (
"context"
"go.dtapp.net/goip"
)
// GinSLogCustom 框架自定义日志
type GinSLogCustom struct {
ipService *goip.Client // IP服务
slog struct {
status bool // 状态
client *SLog // 日志服务
}
}
// GinSLogCustomFun 框架自定义日志驱动
type GinSLogCustomFun func() *GinSLogCustom
// NewGinSLogCustom 创建框架实例化
func NewGinSLogCustom(ctx context.Context, ipService *goip.Client) (*GinSLogCustom, error) {
c := &GinSLogCustom{}
c.ipService = ipService
return c, nil
}

@ -1,7 +1,7 @@
package golog
// ConfigSLogClientFun 日志配置
func (c *GinCustomClient) ConfigSLogClientFun(sLogFun SLogFun) {
func (c *GinSLogCustom) ConfigSLogClientFun(sLogFun SLogFun) {
sLog := sLogFun()
if sLog != nil {
c.slog.client = sLog
@ -10,7 +10,7 @@ func (c *GinCustomClient) ConfigSLogClientFun(sLogFun SLogFun) {
}
// ConfigSLogResultClientFun 日志配置然后返回
func (c *GinCustomClient) ConfigSLogResultClientFun(sLogFun SLogFun) *GinCustomClient {
func (c *GinSLogCustom) ConfigSLogResultClientFun(sLogFun SLogFun) *GinSLogCustom {
sLog := sLogFun()
if sLog != nil {
c.slog.client = sLog

@ -41,7 +41,7 @@ type GinCustomClientGinRecordOperation struct {
}
// GinRecord 记录日志
func (c *GinCustomClient) GinRecord(ginCtx *gin.Context) *GinCustomClientGinRecordOperation {
func (c *GinSLogCustom) GinRecord(ginCtx *gin.Context) *GinCustomClientGinRecordOperation {
operation := &GinCustomClientGinRecordOperation{
slogClient: c.slog.client,
ipService: c.ipService,

@ -40,7 +40,7 @@ type ginSLog struct {
}
// record 记录日志
func (c *GinClient) record(msg string, data ginSLog) {
func (c *GinSLog) record(msg string, data ginSLog) {
c.slog.client.WithTraceIdStr(data.TraceID).Info(msg,
"request_time", data.RequestTime,
"request_uri", data.RequestUri,
@ -69,7 +69,7 @@ func (c *GinClient) record(msg string, data ginSLog) {
)
}
func (c *GinClient) recordJson(ginCtx *gin.Context, traceId string, requestTime time.Time, paramsBody gorequest.Params, responseCode int, responseBody string, startTime, endTime int64, ipInfo goip.AnalyseResult) {
func (c *GinSLog) recordJson(ginCtx *gin.Context, traceId string, requestTime time.Time, paramsBody gorequest.Params, responseCode int, responseBody string, startTime, endTime int64, ipInfo goip.AnalyseResult) {
data := ginSLog{
TraceID: traceId, //【系统】跟踪编号
RequestTime: requestTime, //【请求】时间
@ -102,7 +102,7 @@ func (c *GinClient) recordJson(ginCtx *gin.Context, traceId string, requestTime
c.record("json", data)
}
func (c *GinClient) recordXml(ginCtx *gin.Context, traceId string, requestTime time.Time, requestBody []byte, paramsBody gorequest.Params, responseCode int, responseBody string, startTime, endTime int64, ipInfo goip.AnalyseResult) {
func (c *GinSLog) recordXml(ginCtx *gin.Context, traceId string, requestTime time.Time, requestBody []byte, paramsBody gorequest.Params, responseCode int, responseBody string, startTime, endTime int64, ipInfo goip.AnalyseResult) {
data := ginSLog{
TraceID: traceId, //【系统】跟踪编号
RequestTime: requestTime, //【请求】时间

@ -9,9 +9,9 @@ require (
go.dtapp.net/dorm v1.0.55
go.dtapp.net/goip v1.0.43
go.dtapp.net/gojson v1.0.2
go.dtapp.net/gorequest v1.0.40
go.dtapp.net/gorequest v1.0.41
go.dtapp.net/gotime v1.0.6
go.dtapp.net/gotrace_id v1.0.6
go.dtapp.net/gotrace_id v1.0.8
go.dtapp.net/gourl v1.0.0
)
@ -57,7 +57,7 @@ require (
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/yusufpapurcu/wmi v1.2.3 // indirect
go.dtapp.net/gorandom v1.0.2 // indirect
go.dtapp.net/gostring v1.0.12 // indirect
go.dtapp.net/gostring v1.0.13 // indirect
golang.org/x/arch v0.6.0 // indirect
golang.org/x/crypto v0.17.0 // indirect
golang.org/x/mod v0.14.0 // indirect
@ -66,8 +66,9 @@ require (
golang.org/x/sys v0.15.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.16.1 // indirect
google.golang.org/protobuf v1.31.0 // indirect
google.golang.org/protobuf v1.32.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gorm.io/datatypes v1.2.0 // indirect
gorm.io/driver/mysql v1.5.2 // indirect

@ -56,7 +56,6 @@ github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0kt
github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0=
github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
@ -144,14 +143,14 @@ go.dtapp.net/gojson v1.0.2 h1:NjslBOhAK3XvJepkML7LXcJRPtSfp3rDXGK/29VlDBw=
go.dtapp.net/gojson v1.0.2/go.mod h1:U0Vd2iSLKqdyg6oungBJVHxuYswTbeQVjruQC3/JqQ4=
go.dtapp.net/gorandom v1.0.2 h1:08BdcBP/fQiRw2Ii0OXATSTtObwNydlDlqc/j/u5O8Q=
go.dtapp.net/gorandom v1.0.2/go.mod h1:ZPdgalKpvFV/ATQqR0k4ns/F/IpITAZpx6WkWirr5Y8=
go.dtapp.net/gorequest v1.0.40 h1:11WPUWbIb0AZztfALXTeeu9yPwtQG2LNkWm/5hGZGxc=
go.dtapp.net/gorequest v1.0.40/go.mod h1:t9GF4hMOd/UnNpX5ntHKM4hazy4+cBEcc0rGVzdK83Y=
go.dtapp.net/gostring v1.0.12 h1:r1gwy4sa3SZAPJLMXBeYu7zgZLThA9a06SwRnJ1dlnA=
go.dtapp.net/gostring v1.0.12/go.mod h1:QDO8ApzmwFYzlcpA7lQxSO5ofjQZDmbshhRxQWihzyM=
go.dtapp.net/gorequest v1.0.41 h1:IaWPZ4oYEGsFQdnZrJseY+ytxyAcqtrOmwRsm+g5K2s=
go.dtapp.net/gorequest v1.0.41/go.mod h1:iX5s9j4EzQC+6ShOIK3+GPvjjq9fN+7Y/wj6XV8sbQc=
go.dtapp.net/gostring v1.0.13 h1:Z4R6f9q9arQlkSGNywVQssxxv0LkjHsRjHt/hfwO6/M=
go.dtapp.net/gostring v1.0.13/go.mod h1:qgEjuf0/TFC3ZtvZ9y5tWHBSmV1GmlKiRxhJYJih9uk=
go.dtapp.net/gotime v1.0.6 h1:f8YowUxpZtJbYawe5s5PmvGxRj61ydlzxAPYr5Fcetg=
go.dtapp.net/gotime v1.0.6/go.mod h1:Gq7eNLr2iMLP18UNWONRq4V3Uhf/ADp4bIrS+Tc6ktY=
go.dtapp.net/gotrace_id v1.0.6 h1:q6s8jy50vt1820b69JKQaFqbhGS5yJGMVtocwOGOPO0=
go.dtapp.net/gotrace_id v1.0.6/go.mod h1:o5kSzNK4s3GrrKpkRKXtAhArtBG1e5N5O5KGPlBlWG4=
go.dtapp.net/gotrace_id v1.0.8 h1:cNsPYzOz55B8SKit1smz5b03clr3CVaSCrFns9oOruU=
go.dtapp.net/gotrace_id v1.0.8/go.mod h1:tJzdWgm+8baWZa8K84GdiD99iPguXrn1CehFSh2W0OM=
go.dtapp.net/gourl v1.0.0 h1:Zbe0GiMFyyRy2+bjbVsYulakH5d58w3CDZkUPonlMoQ=
go.dtapp.net/gourl v1.0.0/go.mod h1:x9A/pJ3iKDTb6Gu2RtJy2iHg56IowXIcIGQdogqpGjs=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
@ -178,9 +177,8 @@ golang.org/x/tools v0.16.1 h1:TLyB3WofjdOEepBHAU20JdNC1Zbg87elYofWYAY5oZA=
golang.org/x/tools v0.16.1/go.mod h1:kYVVN6I1mBNoB1OX+noeBjbRk4IUEPa7JJ+TJMEooJ0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I=
google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

Loading…
Cancel
Save