From 76e459ffcc8a58962fc714d4cd17ad58a5093b1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Wed, 24 Jul 2024 22:25:40 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dpanic?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wrapper/gorm_v2.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/wrapper/gorm_v2.go b/wrapper/gorm_v2.go index 9be5188..9a74a36 100644 --- a/wrapper/gorm_v2.go +++ b/wrapper/gorm_v2.go @@ -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 ...