diff --git a/database/gdb/gdb.go b/database/gdb/gdb.go index e6b88dfd5..030d9a336 100644 --- a/database/gdb/gdb.go +++ b/database/gdb/gdb.go @@ -152,8 +152,8 @@ type DB interface { GetGroup() string // See Core.GetGroup. SetDryRun(enabled bool) // See Core.SetDryRun. GetDryRun() bool // See Core.GetDryRun. - SetLogger(logger Logger) // See Core.SetLogger. - GetLogger() Logger // See Core.GetLogger. + SetLogger(logger *glog.Logger) // See Core.SetLogger. + GetLogger() *glog.Logger // See Core.GetLogger. GetConfig() *ConfigNode // See Core.GetConfig. SetMaxIdleConnCount(n int) // See Core.SetMaxIdleConnCount. SetMaxOpenConnCount(n int) // See Core.SetMaxOpenConnCount. @@ -179,7 +179,7 @@ type Core struct { debug *gtype.Bool // Enable debug mode for the database, which can be changed in runtime. cache *gcache.Cache // Cache manager, SQL result cache only. schema *gtype.String // Custom schema for this object. - logger Logger // Logger for logging functionality. + logger *glog.Logger // Logger for logging functionality. config *ConfigNode // Current config node. } @@ -347,7 +347,7 @@ func New(group ...string) (db DB, err error) { debug: gtype.NewBool(), cache: gcache.New(), schema: gtype.NewString(), - logger: LoggerImp{glog.New()}, + logger: glog.New(), config: node, } if v, ok := driverMap[node.Type]; ok { diff --git a/database/gdb/gdb_core_config.go b/database/gdb/gdb_core_config.go index 3f5fb818e..7a8e45443 100644 --- a/database/gdb/gdb_core_config.go +++ b/database/gdb/gdb_core_config.go @@ -8,6 +8,7 @@ package gdb import ( "fmt" + "github.com/gogf/gf/os/glog" "sync" "time" @@ -133,12 +134,12 @@ func IsConfigured() bool { } // SetLogger sets the logger for orm. -func (c *Core) SetLogger(logger Logger) { +func (c *Core) SetLogger(logger *glog.Logger) { c.logger = logger } -// GetLogger returns the logger of the orm. -func (c *Core) GetLogger() Logger { +// GetLogger returns the (logger) of the orm. +func (c *Core) GetLogger() *glog.Logger { return c.logger } diff --git a/database/gdb/gdb_core_logger.go b/database/gdb/gdb_core_logger.go deleted file mode 100644 index e9b5a3fb8..000000000 --- a/database/gdb/gdb_core_logger.go +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright GoFrame Author(https://goframe.org). All Rights Reserved. -// -// This Source Code Form is subject to the terms of the MIT License. -// If a copy of the MIT was not distributed with this file, -// You can obtain one at https://github.com/gogf/gf. - -package gdb - -import ( - "context" - "github.com/gogf/gf/os/glog" -) - -// LoggerImp is the default implementation of interface Logger for DB. -type LoggerImp struct { - *glog.Logger -} - -// Error implements function Error for interface Logger. -func (l LoggerImp) Error(ctx context.Context, s string) { - l.Ctx(ctx).Error(s) -} - -// Debug implements function Debug for interface Logger. -func (l LoggerImp) Debug(ctx context.Context, s string) { - l.Ctx(ctx).Debug(s) -} diff --git a/database/gdb/gdb_z_mysql_ctx_test.go b/database/gdb/gdb_z_mysql_ctx_test.go index 9143bab77..0d3cf753a 100644 --- a/database/gdb/gdb_z_mysql_ctx_test.go +++ b/database/gdb/gdb_z_mysql_ctx_test.go @@ -30,7 +30,7 @@ func Test_Ctx(t *testing.T) { } func Test_Ctx_Query(t *testing.T) { - db.GetLogger().(gdb.LoggerImp).SetCtxKeys("SpanId", "TraceId") + db.GetLogger().SetCtxKeys("SpanId", "TraceId") gtest.C(t, func(t *gtest.T) { db.SetDebug(true) defer db.SetDebug(false) @@ -48,7 +48,7 @@ func Test_Ctx_Query(t *testing.T) { func Test_Ctx_Model(t *testing.T) { table := createInitTable() defer dropTable(table) - db.GetLogger().(gdb.LoggerImp).SetCtxKeys("SpanId", "TraceId") + db.GetLogger().SetCtxKeys("SpanId", "TraceId") gtest.C(t, func(t *gtest.T) { db.SetDebug(true) defer db.SetDebug(false) diff --git a/frame/gins/gins_database.go b/frame/gins/gins_database.go index 1bb55d049..dc49a18a6 100644 --- a/frame/gins/gins_database.go +++ b/frame/gins/gins_database.go @@ -132,10 +132,8 @@ func Database(name ...string) gdb.DB { loggerConfigMap = Config().GetMap(configNodeKey) } if len(loggerConfigMap) > 0 { - if logger, ok := db.GetLogger().(gdb.LoggerImp); ok { - if err := logger.SetConfigWithMap(loggerConfigMap); err != nil { - panic(err) - } + if err := db.GetLogger().SetConfigWithMap(loggerConfigMap); err != nil { + panic(err) } } }