升级数据库日志, 增加sql类型

This commit is contained in:
白茶清欢 2024-07-25 13:48:35 +08:00
parent d6b517ea7a
commit 8ae4053b24

View File

@ -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()
}