From 7ecc9ad8a47f2a48925ebca74ba44ca8a7e8963b Mon Sep 17 00:00:00 2001 From: loser <1711788888@qq.com> Date: Tue, 6 Sep 2022 16:41:52 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=20'gorm=5Ftest.go'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gorm_test.go | 45 --------------------------------------------- 1 file changed, 45 deletions(-) delete mode 100644 gorm_test.go diff --git a/gorm_test.go b/gorm_test.go deleted file mode 100644 index 836bd84..0000000 --- a/gorm_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package logger - -import ( - "gitee.ltd/lxh/logger/log" - "gorm.io/driver/mysql" - "gorm.io/gorm" - gl "gorm.io/gorm/logger" - "testing" - "time" -) - -func TestGormLogger(t *testing.T) { - dsn := "saas:saas123@tcp(10.11.0.10:3307)/saas_tenant?charset=utf8mb4&parseTime=True&loc=Local" - - engine, err := gorm.Open(mysql.Open(dsn), &gorm.Config{Logger: DefaultGormLogger()}) - if err != nil { - log.Panicf("mysql connect error: %s", err.Error()) - } - - var count int64 - if err := engine.Table("t_tenant").Count(&count).Error; err != nil { - t.Log(err) - } - t.Logf("count: %d", count) -} - -func TestGormLoggerWithConfig(t *testing.T) { - dsn := "saas:saas123@tcp(10.11.0.10:3307)/saas_tenant?charset=utf8mb4&parseTime=True&loc=Local" - - engine, err := gorm.Open(mysql.Open(dsn), &gorm.Config{Logger: NewGormLoggerWithConfig(gl.Config{ - SlowThreshold: time.Second, // Slow SQL threshold - IgnoreRecordNotFoundError: false, // 忽略没找到结果的错误 - LogLevel: gl.Warn, // Log level - Colorful: false, // Disable color - })}) - if err != nil { - log.Panicf("mysql connect error: %s", err.Error()) - } - - var count int64 - if err := engine.Table("t_tenant1").Count(&count).Error; err != nil { - t.Log(err) - } - t.Logf("count: %d", count) -}