修复mysql日志问题
This commit is contained in:
parent
5965faa37f
commit
b387fa6b9a
52
client.go
52
client.go
@ -13,9 +13,6 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/util"
|
||||
|
||||
@ -24,7 +21,6 @@ import (
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"git.zhangdeman.cn/zhangdeman/logger"
|
||||
gormLogger "gorm.io/gorm/logger"
|
||||
|
||||
"gorm.io/driver/mysql"
|
||||
@ -54,7 +50,7 @@ type client struct {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 19:19 2022/6/5
|
||||
func (c *client) AddWithConfigFile(cfgFilePath string) error {
|
||||
func (c *client) AddWithConfigFile(cfgFilePath string, logInstance *zap.Logger) error {
|
||||
var (
|
||||
err error
|
||||
cfg *cfgFile
|
||||
@ -76,10 +72,10 @@ func (c *client) AddWithConfigFile(cfgFilePath string) error {
|
||||
extraFieldList: nil,
|
||||
cfg: Mysql{},
|
||||
}
|
||||
if dbClient.master, err = c.GetDatabaseClient(cfg.Config.Master, nil); nil != err {
|
||||
if dbClient.master, err = c.GetDatabaseClient(cfg.Config.Master, logInstance); nil != err {
|
||||
return err
|
||||
}
|
||||
if dbClient.slave, err = c.GetDatabaseClient(cfg.Config.Slave, nil); nil != err {
|
||||
if dbClient.slave, err = c.GetDatabaseClient(cfg.Config.Slave, logInstance); nil != err {
|
||||
return err
|
||||
}
|
||||
c.lock.Lock()
|
||||
@ -93,10 +89,10 @@ func (c *client) AddWithConfigFile(cfgFilePath string) error {
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 19:19 2022/6/5
|
||||
func (c *client) BatchAddWithConfigDir(cfgDir string) error {
|
||||
func (c *client) BatchAddWithConfigDir(cfgDir string, logInstance *zap.Logger) error {
|
||||
filepathNames, _ := filepath.Glob(filepath.Join(cfgDir, "*"))
|
||||
for i := range filepathNames {
|
||||
if err := c.AddWithConfigFile(filepathNames[i]); nil != err {
|
||||
if err := c.AddWithConfigFile(filepathNames[i], logInstance); nil != err {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@ -208,44 +204,6 @@ func (c *client) GetSlaveClient(ctx *gin.Context, dbFlag string) (*gorm.DB, erro
|
||||
return session, nil
|
||||
}
|
||||
|
||||
// getLogInstance 获取日志实例
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
//
|
||||
// Date : 20:23 2022/6/5
|
||||
func (c *client) getLogInstance(logConf *logger.InputLogConfig) (*zap.Logger, error) {
|
||||
if nil == logConf {
|
||||
return nil, nil
|
||||
}
|
||||
logConfList := []logger.SetLoggerOptionFunc{
|
||||
logger.WithCallerSkip(logConf.CallerSkip),
|
||||
logger.WithCaller(),
|
||||
logger.WithUseJsonFormat(logConf.UseJson),
|
||||
logger.WithShortCaller(logConf.UseShortFile),
|
||||
}
|
||||
if logConf.Console {
|
||||
logConfList = append(logConfList, logger.WithConsoleOutput())
|
||||
}
|
||||
|
||||
var (
|
||||
err error
|
||||
loggerInstance *zap.Logger
|
||||
splitConfig *logger.RotateLogConfig
|
||||
)
|
||||
if splitConfig, err = logger.NewRotateLogConfig(
|
||||
logConf.Path,
|
||||
logConf.Name,
|
||||
logger.WithDivisionChar(logConf.DivisionChar),
|
||||
logger.WithTimeIntervalType(logConf.TimeIntervalType),
|
||||
logger.WithMaxAge(time.Duration(logConf.MaxAge)*time.Second)); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
if loggerInstance, err = logger.NewLogger(zapcore.Level(logConf.LogLevel), splitConfig, logConfList...); nil != err {
|
||||
return nil, err
|
||||
}
|
||||
return loggerInstance, nil
|
||||
}
|
||||
|
||||
// getGormClient 获取GORM client方法
|
||||
//
|
||||
// Author : go_developer@163.com<白茶清欢>
|
||||
|
Loading…
Reference in New Issue
Block a user