完成日志写入zinc的能力

This commit is contained in:
2025-04-27 13:18:30 +08:00
parent 21efb0bb85
commit ea78e582bb
6 changed files with 198 additions and 183 deletions

View File

@ -83,6 +83,7 @@ type InputLogConfig struct {
UseShortFile bool `json:"use_short_file" yaml:"use_short_file"` // 是否使用短文件格式
CallerSkip int `json:"caller_skip" yaml:"caller_skip"` // 日志记录的文件跳过多少层
MaxAge int `json:"max_age" yaml:"max_age"` // 日志最长保存时间, 单位 : 秒
ZincSyncConfig *ZincConfig `json:"zinc_sync_config" yaml:"zinc_sync_config"` // 日志同步至zinc的配置
}
// GetLogInstanceFromInputConfig 从输入配置获取日志实例
@ -103,6 +104,8 @@ func GetLogInstanceFromInputConfig(logConf *InputLogConfig) (*zap.Logger, error)
if logConf.Console {
logConfList = append(logConfList, WithConsoleOutput())
}
// 配置zinc日志同步
logConfList = append(logConfList, WithZincLogCollect(logConf.ZincSyncConfig))
var (
err error
@ -149,3 +152,25 @@ func inputLevel2ZapLevel(inputLoggerLevel consts.LogLevel) zapcore.Level {
}
return loggerLevel
}
// ZincConfig zinc服务配置
type ZincConfig struct {
Authorization string `json:"authorization" dc:"授权secret,生成方式base64(user:password)"`
Domain string `json:"domain" dc:"zinc服务域名"`
Timeout int `json:"timeout" dc:"超时时间,单位毫秒,默认5000"`
Async bool `json:"async" dc:"数据异步写入"`
Index string `json:"index" dc:"日志使用的索引"`
CreateType string `json:"create_type" dc:"日志同步的类型: single - 单个同步 batch - 批量创建"`
BufferSize int `json:"buffer_size" dc:"批量创建时, 数据缓存buffer大小, 默认1000"`
ForceSyncTime int `json:"force_sync_time" dc:"批量同步日志时,强制同步的时间间隔,buffer没满也会强制同步, 单位: 秒"`
}
const (
DefaultTimeout = 5000 // 默认超时时间
DefaultBufferSize = 1000 // 默认buffer大小
)
const (
CreateTypeSingle = "single" // 逐条日志同步
CreateTypeBatch = "batch" // 批量日志同步
)