引入lumberjack和fluentbit自动分发
This commit is contained in:
@@ -2,8 +2,65 @@
|
||||
|
||||
package serverconfigs
|
||||
|
||||
const (
|
||||
DefaultAccessLogRotateMaxSizeMB = 256
|
||||
DefaultAccessLogRotateMaxBackups = 14
|
||||
DefaultAccessLogRotateMaxAgeDays = 7
|
||||
)
|
||||
|
||||
// AccessLogRotateConfig 文件轮转配置。
|
||||
type AccessLogRotateConfig struct {
|
||||
MaxSizeMB int `yaml:"maxSizeMB" json:"maxSizeMB"` // 单文件最大大小(MB)
|
||||
MaxBackups int `yaml:"maxBackups" json:"maxBackups"` // 保留历史文件数
|
||||
MaxAgeDays int `yaml:"maxAgeDays" json:"maxAgeDays"` // 保留天数
|
||||
Compress *bool `yaml:"compress" json:"compress"` // 是否压缩历史文件
|
||||
LocalTime *bool `yaml:"localTime" json:"localTime"` // 轮转时间使用本地时区
|
||||
}
|
||||
|
||||
// AccessLogFileStorageConfig 文件存储配置
|
||||
type AccessLogFileStorageConfig struct {
|
||||
Path string `yaml:"path" json:"path"` // 文件路径,支持变量:${year|month|week|day|hour|minute|second}
|
||||
AutoCreate bool `yaml:"autoCreate" json:"autoCreate"` // 是否自动创建目录
|
||||
Path string `yaml:"path" json:"path"` // 文件路径,支持变量:${year|month|week|day|hour|minute|second}
|
||||
AutoCreate bool `yaml:"autoCreate" json:"autoCreate"` // 是否自动创建目录
|
||||
Rotate *AccessLogRotateConfig `yaml:"rotate" json:"rotate"` // 文件轮转配置
|
||||
}
|
||||
|
||||
// NewDefaultAccessLogRotateConfig 默认轮转配置。
|
||||
func NewDefaultAccessLogRotateConfig() *AccessLogRotateConfig {
|
||||
compress := false
|
||||
localTime := true
|
||||
return &AccessLogRotateConfig{
|
||||
MaxSizeMB: DefaultAccessLogRotateMaxSizeMB,
|
||||
MaxBackups: DefaultAccessLogRotateMaxBackups,
|
||||
MaxAgeDays: DefaultAccessLogRotateMaxAgeDays,
|
||||
Compress: &compress,
|
||||
LocalTime: &localTime,
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize 归一化轮转配置,空值/非法值回退默认。
|
||||
func (c *AccessLogRotateConfig) Normalize() *AccessLogRotateConfig {
|
||||
defaultConfig := NewDefaultAccessLogRotateConfig()
|
||||
if c == nil {
|
||||
return defaultConfig
|
||||
}
|
||||
|
||||
if c.MaxSizeMB > 0 {
|
||||
defaultConfig.MaxSizeMB = c.MaxSizeMB
|
||||
}
|
||||
if c.MaxBackups > 0 {
|
||||
defaultConfig.MaxBackups = c.MaxBackups
|
||||
}
|
||||
if c.MaxAgeDays > 0 {
|
||||
defaultConfig.MaxAgeDays = c.MaxAgeDays
|
||||
}
|
||||
if c.Compress != nil {
|
||||
v := *c.Compress
|
||||
defaultConfig.Compress = &v
|
||||
}
|
||||
if c.LocalTime != nil {
|
||||
v := *c.LocalTime
|
||||
defaultConfig.LocalTime = &v
|
||||
}
|
||||
|
||||
return defaultConfig
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user