diff --git a/logger/wrapper/gorm_v2.go b/logger/wrapper/gorm_v2.go index aea41d6..0a767f4 100644 --- a/logger/wrapper/gorm_v2.go +++ b/logger/wrapper/gorm_v2.go @@ -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, diff --git a/middleware/mysql/client.go b/middleware/mysql/client.go index ce286e0..86ff69d 100644 --- a/middleware/mysql/client.go +++ b/middleware/mysql/client.go @@ -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)