From 8ae4053b241be1df88f5449af897cb68567f8378 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Thu, 25 Jul 2024 13:48:35 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E6=97=A5=E5=BF=97,=20=E5=A2=9E=E5=8A=A0sql=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wrapper/gorm_v2.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wrapper/gorm_v2.go b/wrapper/gorm_v2.go index ec34f3b..558fa40 100644 --- a/wrapper/gorm_v2.go +++ b/wrapper/gorm_v2.go @@ -9,6 +9,7 @@ package wrapper import ( "context" + "fmt" "strings" "time" @@ -175,6 +176,13 @@ func (g *Gorm) write(ctx context.Context, message string, level string, data map if nil == data { data = make(map[string]any) } + if nil != data["sql"] { + sqlStr := strings.TrimSpace(fmt.Sprintf("%v", data["sql"])) + sqlArr := strings.Split(sqlStr, " ") + if len(sqlArr) > 0 { + message = fmt.Sprintf("【%v】" + message) + } + } if nil == g.outCtx { g.outCtx = context.Background() }