feat: 增加数据库日志配置

This commit is contained in:
zhengkunwang223 2023-04-05 20:17:52 +08:00 committed by zhengkunwang223
parent 04a76fd94d
commit 947293f34e

View File

@ -2,6 +2,8 @@ package db
import (
"fmt"
"gorm.io/gorm/logger"
"log"
"os"
"time"
@ -24,8 +26,19 @@ func Init() {
}
}
newLogger := logger.New(
log.New(os.Stdout, "\r\n", log.LstdFlags),
logger.Config{
SlowThreshold: time.Second,
LogLevel: logger.Silent,
IgnoreRecordNotFoundError: true,
Colorful: false,
},
)
db, err := gorm.Open(sqlite.Open(fullPath), &gorm.Config{
DisableForeignKeyConstraintWhenMigrating: true,
Logger: newLogger,
})
if err != nil {
panic(err)