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 {