修复mysql日志问题
This commit is contained in:
parent
f62e82ecd0
commit
f0cfac27b6
@ -32,6 +32,7 @@ func NewGormV2(loggerLevel zapcore.Level, consoleOutput bool, encoder zapcore.En
|
|||||||
if consoleOutput {
|
if consoleOutput {
|
||||||
logConfList = append(logConfList, logger2.WithConsoleOutput())
|
logConfList = append(logConfList, logger2.WithConsoleOutput())
|
||||||
}
|
}
|
||||||
|
|
||||||
logInstance, err := logger2.NewLogger(loggerLevel, splitConfig, logConfList...)
|
logInstance, err := logger2.NewLogger(loggerLevel, splitConfig, logConfList...)
|
||||||
if nil != err {
|
if nil != err {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -39,6 +40,7 @@ func NewGormV2(loggerLevel zapcore.Level, consoleOutput bool, encoder zapcore.En
|
|||||||
if len(traceIDField) == 0 {
|
if len(traceIDField) == 0 {
|
||||||
traceIDField = "trace_id"
|
traceIDField = "trace_id"
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Gorm{
|
return &Gorm{
|
||||||
instance: logInstance,
|
instance: logInstance,
|
||||||
traceIDField: traceIDField,
|
traceIDField: traceIDField,
|
||||||
|
@ -10,6 +10,8 @@ package mysql
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"git.zhangdeman.cn/zhangdeman/gopkg/logger"
|
||||||
|
|
||||||
"git.zhangdeman.cn/zhangdeman/gopkg/logger/wrapper"
|
"git.zhangdeman.cn/zhangdeman/gopkg/logger/wrapper"
|
||||||
|
|
||||||
"gorm.io/driver/mysql"
|
"gorm.io/driver/mysql"
|
||||||
@ -35,11 +37,19 @@ func GetDatabaseClient(conf *DBConfig, logConf *LogConfig) (*gorm.DB, error) {
|
|||||||
logConf.TraceFieldName = defaultTraceFieldName
|
logConf.TraceFieldName = defaultTraceFieldName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
splitConfigFuncList := []logger.SetRotateLogConfigFunc{
|
||||||
|
logger.WithTimeIntervalType(logConf.SplitConfig.TimeIntervalType),
|
||||||
|
logger.WithDivisionChar(logConf.SplitConfig.DivisionChar),
|
||||||
|
logger.WithMaxAge(logConf.SplitConfig.MaxAge),
|
||||||
|
}
|
||||||
|
|
||||||
|
splitConfig, _ := logger.NewRotateLogConfig(logConf.SplitConfig.LogPath, logConf.SplitConfig.LogFileName, splitConfigFuncList...)
|
||||||
|
|
||||||
if instance.Logger, err = wrapper.NewGormV2(
|
if instance.Logger, err = wrapper.NewGormV2(
|
||||||
logConf.Level,
|
logConf.Level,
|
||||||
logConf.ConsoleOutput,
|
logConf.ConsoleOutput,
|
||||||
logConf.Encoder,
|
logConf.Encoder,
|
||||||
logConf.SplitConfig,
|
splitConfig,
|
||||||
logConf.TraceFieldName,
|
logConf.TraceFieldName,
|
||||||
logConf.Skip); nil != err {
|
logConf.Skip); nil != err {
|
||||||
return nil, CreateDBLogError(err)
|
return nil, CreateDBLogError(err)
|
||||||
|
Loading…
Reference in New Issue
Block a user