🎨 优化日志打印

This commit is contained in:
李寻欢
2023-12-08 11:41:59 +08:00
parent e9212f68cc
commit 58cb76ed75
2 changed files with 10 additions and 6 deletions

View File

@@ -6,9 +6,11 @@ import (
"gorm.io/gorm"
"gorm.io/gorm/logger"
"log"
"os"
"strconv"
)
// MySQL客户端
// MySQL MySQL客户端
var MySQL *gorm.DB
func InitMySQLClient() {
@@ -20,8 +22,10 @@ func InitMySQLClient() {
}
// gorm 配置
gormConfig := gorm.Config{
Logger: logger.Default.LogMode(logger.Info),
gormConfig := gorm.Config{}
// 是否开启调试模式
if flag, _ := strconv.ParseBool(os.Getenv("GORM_DEBUG")); flag {
gormConfig.Logger = logger.Default.LogMode(logger.Info)
}
conn, err := gorm.Open(mysql.New(mysqlConfig), &gormConfig)