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

web log add debug

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