修复日志BUG
This commit is contained in:
@ -21,6 +21,7 @@ import (
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
pkgGinDefine "git.zhangdeman.cn/zhangdeman/gin/define"
|
||||
logger2 "git.zhangdeman.cn/zhangdeman/logger"
|
||||
"gorm.io/gorm/logger"
|
||||
)
|
||||
@ -60,7 +61,7 @@ func NewGormLoggerWithInstance(ctx *gin.Context, dbClient *gorm.DB, instance *za
|
||||
i := &Gorm{
|
||||
dbClient: dbClient,
|
||||
instance: instance,
|
||||
traceIDField: "",
|
||||
traceIDField: pkgGinDefine.TraceIDField,
|
||||
extraCtxFieldList: extraCtxFieldList,
|
||||
flag: "",
|
||||
node: node,
|
||||
@ -139,7 +140,6 @@ func (g *Gorm) Trace(ctx context.Context, begin time.Time, fc func() (string, in
|
||||
}
|
||||
|
||||
dataList := []zap.Field{
|
||||
zap.String(g.traceIDField, g.getTraceID(ctx)),
|
||||
zap.String("db_flag", g.flag),
|
||||
zap.Int64("begin_time", start),
|
||||
zap.Int64("finish_time", end),
|
||||
@ -148,8 +148,10 @@ func (g *Gorm) Trace(ctx context.Context, begin time.Time, fc func() (string, in
|
||||
zap.Int64("affect_rows", affectRows),
|
||||
zap.Error(err),
|
||||
}
|
||||
if len(g.traceIDField) > 0 {
|
||||
dataList = append(dataList, zap.String(g.traceIDField, g.getTraceID(ctx)))
|
||||
}
|
||||
g.write(dataList, "info")
|
||||
|
||||
}
|
||||
|
||||
// write ...
|
||||
@ -177,7 +179,7 @@ func (g *Gorm) write(dataList []zap.Field, level string) {
|
||||
// 补齐 flag、node
|
||||
sql := g.dbClient.Dialector.Explain(g.dbClient.Statement.SQL.String(), g.dbClient.Statement.Vars...)
|
||||
affectRows := g.dbClient.RowsAffected
|
||||
dataList = append(dataList, zap.String("db_node", g.node), zap.String("db_flag", g.flag), zap.String("execute_sql", sql), zap.Int64("affect_rows", affectRows))
|
||||
dataList = append(dataList, zap.String("db_node", g.node), zap.String("execute_sql", sql), zap.Int64("affect_rows", affectRows))
|
||||
message := "SQL执行记录"
|
||||
switch strings.ToLower(level) {
|
||||
case "info":
|
||||
|
Reference in New Issue
Block a user