修复panic

This commit is contained in:
白茶清欢 2024-07-24 22:25:40 +08:00
parent 0bc05b3816
commit 76e459ffcc

View File

@ -143,7 +143,7 @@ func (g *Gorm) Trace(ctx context.Context, begin time.Time, fc func() (string, in
sql, affectRows = fc()
}
g.write(ctx, "SQL执行记录", consts.LogLevelInfo, map[string]any{
logData := map[string]any{
"db_flag": g.flag,
"db_node": g.node,
"begin_time": start,
@ -151,8 +151,12 @@ func (g *Gorm) Trace(ctx context.Context, begin time.Time, fc func() (string, in
"used_time": (end - start) / 1e6,
"sql": sql,
"affect_rows": affectRows,
"err": err.Error(),
})
"err": "",
}
if nil != err {
logData["err"] = err.Error()
}
g.write(ctx, "SQL执行记录", consts.LogLevelInfo, logData)
}
// write ...