🎨优化sql日志打印
All checks were successful
continuous-integration/drone/tag Build is passing

This commit is contained in:
coward 2024-06-13 15:34:22 +08:00
parent 5df6ccefe2
commit 073bcc4a1d

View File

@ -12,8 +12,10 @@ import (
"gorm.io/driver/mysql" "gorm.io/driver/mysql"
"gorm.io/driver/postgres" "gorm.io/driver/postgres"
"gorm.io/gorm" "gorm.io/gorm"
gl "gorm.io/gorm/logger"
"log" "log"
"os" "os"
"time"
"wireguard-dashboard/client" "wireguard-dashboard/client"
"wireguard-dashboard/config" "wireguard-dashboard/config"
) )
@ -69,8 +71,18 @@ func initDatabase() {
dbDialector = sqlite.Open(config.Config.Database.GetDSN()) 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{ 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 { if err != nil {