feat: 升级日志实现, 支持全局存储日志实例

This commit is contained in:
2025-12-31 12:50:26 +08:00
parent 62f5f950e7
commit 6bf92d93bc
4 changed files with 113 additions and 51 deletions

View File

@@ -134,42 +134,6 @@ func getStrVal(ctx context.Context, key string) string {
return ""
}
// GetLogInstanceFromInputConfig 从输入配置获取日志实例
func GetLogInstanceFromInputConfig(logConf *InputLogConfig) (*zap.Logger, error) {
if nil == logConf {
return nil, nil
}
logConfList := []SetLoggerOptionFunc{
WithCallerSkip(logConf.CallerSkip),
WithCaller(),
WithUseJsonFormat(logConf.UseJson),
WithShortCaller(logConf.UseShortFile),
}
if logConf.Console {
logConfList = append(logConfList, WithConsoleOutput())
}
// 配置zinc日志同步
logConfList = append(logConfList, WithZincLogCollect(logConf.ZincSyncConfig))
var (
err error
loggerInstance *zap.Logger
splitConfig *RotateLogConfig
)
if splitConfig, err = NewRotateLogConfig(
logConf.Path,
logConf.Name,
WithDivisionChar(logConf.DivisionChar),
WithTimeIntervalType(logConf.TimeIntervalType),
WithMaxAge(logConf.MaxAge)); nil != err {
return nil, err
}
if loggerInstance, err = NewLogger(logConf.LogLevel, splitConfig, logConfList...); nil != err {
return nil, err
}
return loggerInstance, nil
}
// inputLevel2ZapLevel 输入日志等级转化为zap日志等级
func inputLevel2ZapLevel(inputLoggerLevel LogLevel) zapcore.Level {
inputLoggerLevel = LogLevel(strings.ToUpper(inputLoggerLevel.String()))
@@ -207,7 +171,7 @@ type ZincConfig struct {
const (
DefaultTimeout = 5000 // 默认超时时间
DefaultBufferSize = 1000 // 默认buffer大小
DefaultBufferSize = 1000 // 默认 buffer 大小
DefaultForceFlushLogTime = 1000 // 强制刷新日志的时间间隔, 单位毫秒
)