修复mysql日志问题

This commit is contained in:
白茶清欢 2021-08-15 01:07:02 +08:00
parent f62e82ecd0
commit f0cfac27b6
2 changed files with 13 additions and 1 deletions

View File

@ -32,6 +32,7 @@ func NewGormV2(loggerLevel zapcore.Level, consoleOutput bool, encoder zapcore.En
if consoleOutput {
logConfList = append(logConfList, logger2.WithConsoleOutput())
}
logInstance, err := logger2.NewLogger(loggerLevel, splitConfig, logConfList...)
if nil != err {
return nil, err
@ -39,6 +40,7 @@ func NewGormV2(loggerLevel zapcore.Level, consoleOutput bool, encoder zapcore.En
if len(traceIDField) == 0 {
traceIDField = "trace_id"
}
return &Gorm{
instance: logInstance,
traceIDField: traceIDField,

View File

@ -10,6 +10,8 @@ package mysql
import (
"fmt"
"git.zhangdeman.cn/zhangdeman/gopkg/logger"
"git.zhangdeman.cn/zhangdeman/gopkg/logger/wrapper"
"gorm.io/driver/mysql"
@ -35,11 +37,19 @@ func GetDatabaseClient(conf *DBConfig, logConf *LogConfig) (*gorm.DB, error) {
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(
logConf.Level,
logConf.ConsoleOutput,
logConf.Encoder,
logConf.SplitConfig,
splitConfig,
logConf.TraceFieldName,
logConf.Skip); nil != err {
return nil, CreateDBLogError(err)