From 073bcc4a1df05e2e3cd93652bdbfcc0fc7c46c57 Mon Sep 17 00:00:00 2001 From: coward Date: Thu, 13 Jun 2024 15:34:22 +0800 Subject: [PATCH] =?UTF-8?q?:art:=E4=BC=98=E5=8C=96sql=E6=97=A5=E5=BF=97?= =?UTF-8?q?=E6=89=93=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- initialize/init.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/initialize/init.go b/initialize/init.go index 63c3c54..3c4fd26 100644 --- a/initialize/init.go +++ b/initialize/init.go @@ -12,8 +12,10 @@ import ( "gorm.io/driver/mysql" "gorm.io/driver/postgres" "gorm.io/gorm" + gl "gorm.io/gorm/logger" "log" "os" + "time" "wireguard-dashboard/client" "wireguard-dashboard/config" ) @@ -69,8 +71,18 @@ func initDatabase() { dbDialector = sqlite.Open(config.Config.Database.GetDSN()) } + logLevel := gl.Info + if os.Getenv("GIN_MODE") == "release" { + logLevel = gl.Error + } + db, err := gorm.Open(dbDialector, &gorm.Config{ - Logger: logger.DefaultGormLogger(), + Logger: logger.NewGormLoggerWithConfig(gl.Config{ + SlowThreshold: time.Second, // Slow SQL threshold + IgnoreRecordNotFoundError: false, // 忽略没找到结果的错误 + LogLevel: logLevel, // Log level + Colorful: false, // Disable color + }), }) if err != nil {