mirror of
https://gitee.com/johng/gf
synced 2026-07-06 13:42:46 +08:00
revert ORM logger from interface to glog.Logger
This commit is contained in:
@ -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 {
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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)
|
||||
}
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user