提交 444c46da authored 作者: mooncake's avatar mooncake

web log add debug

上级 cc4191eb
package config package config
import ( import (
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/config"
"strings" "strings"
"sync" "sync"
"time" "time"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/email/config"
"github.com/jinzhu/copier" "github.com/jinzhu/copier"
"gitlab.wanzhuangkj.com/tush/xpkg/pkg/oss" "gitlab.wanzhuangkj.com/tush/xpkg/pkg/oss"
) )
...@@ -271,6 +272,7 @@ type IDGeneration struct { ...@@ -271,6 +272,7 @@ type IDGeneration struct {
type WebLog struct { type WebLog struct {
Enable bool `yaml:"enable" json:"enable" mapstructure:"enable"` Enable bool `yaml:"enable" json:"enable" mapstructure:"enable"`
Debug bool `yaml:"debug" json:"debug" mapstructure:"debug"`
Schema string `yaml:"schema" json:"schema" mapstructure:"schema"` Schema string `yaml:"schema" json:"schema" mapstructure:"schema"`
IgnorePaths []string `yaml:"ignorePaths" json:"ignorePaths" mapstructure:"ignorePaths"` IgnorePaths []string `yaml:"ignorePaths" json:"ignorePaths" mapstructure:"ignorePaths"`
} }
......
...@@ -25,6 +25,7 @@ app: ...@@ -25,6 +25,7 @@ app:
cacheType: "memory" cacheType: "memory"
webLog: webLog:
enable: true enable: true
debug: true
schema: operator schema: operator
ignorePaths: ignorePaths:
ipRateLimiter: ipRateLimiter:
...@@ -78,7 +79,7 @@ rd: ...@@ -78,7 +79,7 @@ rd:
healthy: true healthy: true
ephemeral: true ephemeral: true
username: nacos username: nacos
password: 4RSl6H3w!xEs password:
database: database:
- name: "operator" - name: "operator"
...@@ -115,7 +116,7 @@ redis: ...@@ -115,7 +116,7 @@ redis:
auth: auth:
enable: true enable: true
expire: 6h expire: 6h
signKey: 6m2KywHIPEaWWIxffGpp8Dfl3z5SjE5WeeDStc1T64klnpoAqHrHN01vneteCAGE signKey:
cron: cron:
type: xxl # db or xxl type: xxl # db or xxl
...@@ -128,8 +129,8 @@ cron: ...@@ -128,8 +129,8 @@ cron:
oss: oss:
endpoint: https://oss-cn-hangzhou.aliyuncs.com endpoint: https://oss-cn-hangzhou.aliyuncs.com
access-key-id: LTAI5tPgFMJTX3BDw9UdAu5i access-key-id:
access-key-secret: vi0YTDW7NjuRnPjA9yJMbH08ugQqia access-key-secret:
bucket-name: dev-athena bucket-name: dev-athena
base-path: qitu/admin base-path: qitu/admin
region-id: oss-cn-hangzhou region-id: oss-cn-hangzhou
...@@ -201,8 +202,8 @@ extend: ...@@ -201,8 +202,8 @@ extend:
intake: "/front/entry/register" intake: "/front/entry/register"
intake-query: "/front/entry/registerInfo" intake-query: "/front/entry/registerInfo"
intake-qr-code: "/front/entry/getAuthQrCode" intake-qr-code: "/front/entry/getAuthQrCode"
app-id: "9285809280" app-id: ""
app-secret: "dx2LE3dovc51ycjqiezOcd0r0c9taKTeAqCVaR4LBs4" app-secret: ""
pay-center: pay-center:
server-addr: "http://service-pay.wz-service:18306" # 支付中心 server-addr: "http://service-pay.wz-service:18306" # 支付中心
dg-pay: "/pay/dougong" # 斗拱支付 dg-pay: "/pay/dougong" # 斗拱支付
......
...@@ -29,6 +29,7 @@ import ( ...@@ -29,6 +29,7 @@ import (
var ( var (
schema string schema string
enable bool = false enable bool = false
debug bool = false
ignore = make(map[string]struct{}) ignore = make(map[string]struct{})
) )
...@@ -72,10 +73,7 @@ func WebLogInterceptor() func(c *gin.Context) { ...@@ -72,10 +73,7 @@ func WebLogInterceptor() func(c *gin.Context) {
} }
c.Next() c.Next()
if ok { if ok {
// respCode = c.GetInt(ctxUtils.KeyRspCode)
// if respCode <= 0 {
rsp = entity.GetCopyRsp(c) rsp = entity.GetCopyRsp(c)
// }
} }
} }
} }
...@@ -104,6 +102,7 @@ func Init() { ...@@ -104,6 +102,7 @@ func Init() {
copier.Copy(&webLogCfg, c.App.WebLog) copier.Copy(&webLogCfg, c.App.WebLog)
}) })
enable = webLogCfg.Enable enable = webLogCfg.Enable
debug = webLogCfg.Debug
if !webLogCfg.Enable { if !webLogCfg.Enable {
return return
} }
...@@ -134,19 +133,32 @@ func Init() { ...@@ -134,19 +133,32 @@ func Init() {
return nil return nil
} }
insertFn := func() error { insertFn := func() error {
if debug {
if err := webLogDaoInstance.CreateSlice(ctx, ors); err != nil {
logger.Error("[webLog] insert fail detail", logger.Err(err), ctxUtils.CtxTraceIDField(ctx))
return err
}
} else {
if err := webLogDaoInstance.CreateSliceSilent(ctx, ors); err != nil { if err := webLogDaoInstance.CreateSliceSilent(ctx, ors); err != nil {
logger.Error("[webLog] insert fail detail", logger.Err(err), ctxUtils.CtxTraceIDField(ctx)) logger.Error("[webLog] insert fail detail", logger.Err(err), ctxUtils.CtxTraceIDField(ctx))
return err return err
} }
}
return nil return nil
} }
go func() { go func() {
if debug {
logger.Info("[webLog]batch insert start")
}
if err := retryUtils.Retry(insertFn, retryUtils.RetryTimes(10), retryUtils.RetryWithLinearBackoff(32*time.Minute)); err != nil { if err := retryUtils.Retry(insertFn, retryUtils.RetryTimes(10), retryUtils.RetryWithLinearBackoff(32*time.Minute)); err != nil {
logger.Error("[webLog] insert fail", logger.String("err", err.Error()), ctxUtils.CtxTraceIDField(ctx)) logger.Error("[webLog] insert fail", logger.String("err", err.Error()), ctxUtils.CtxTraceIDField(ctx))
for _, or := range ors { for _, or := range ors {
logger.Error("[webLog] insert fail detail", logger.String("user_id", or.UserID.String()), logger.String("operate", or.Operate), ctxUtils.CtxTraceIDField(ctx)) logger.Error("[webLog] insert fail detail", logger.String("user_id", or.UserID.String()), logger.String("operate", or.Operate), ctxUtils.CtxTraceIDField(ctx))
} }
} }
if debug {
logger.Info("[webLog]batch insert success")
}
}() }()
return nil return nil
}) })
...@@ -185,6 +197,10 @@ func (x *webLogDao) CreateSliceSilent(ctx context.Context, ors []*WebLog) error ...@@ -185,6 +197,10 @@ func (x *webLogDao) CreateSliceSilent(ctx context.Context, ors []*WebLog) error
return x.db.WithContext(ctx).Session(&gorm.Session{Logger: glogger.Discard}).Create(ors).Error return x.db.WithContext(ctx).Session(&gorm.Session{Logger: glogger.Discard}).Create(ors).Error
} }
func (x *webLogDao) CreateSlice(ctx context.Context, ors []*WebLog) error {
return x.db.WithContext(ctx).Create(ors).Error
}
func getUserType(c *gin.Context) int { func getUserType(c *gin.Context) int {
val := c.Value(ctxUtils.KeyUType) val := c.Value(ctxUtils.KeyUType)
if val != nil { if val != nil {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论