引入lumberjack和fluentbit自动分发
This commit is contained in:
@@ -19,6 +19,7 @@ type NSNodeConfig struct {
|
||||
AccessLogRef *NSAccessLogRef `yaml:"accessLogRef" json:"accessLogRef"`
|
||||
AccessLogWriteTargets *serverconfigs.AccessLogWriteTargets `yaml:"accessLogWriteTargets" json:"accessLogWriteTargets"`
|
||||
AccessLogFilePath string `yaml:"accessLogFilePath" json:"accessLogFilePath"`
|
||||
AccessLogRotate *serverconfigs.AccessLogRotateConfig `yaml:"accessLogRotate" json:"accessLogRotate"`
|
||||
RecursionConfig *NSRecursionConfig `yaml:"recursionConfig" json:"recursionConfig"`
|
||||
DDoSProtection *ddosconfigs.ProtectionConfig `yaml:"ddosProtection" json:"ddosProtection"`
|
||||
AllowedIPs []string `yaml:"allowedIPs" json:"allowedIPs"`
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ func NewGlobalServerConfig() *GlobalServerConfig {
|
||||
config.HTTPAccessLog.EnableResponseHeaders = true
|
||||
config.HTTPAccessLog.EnableCookies = true
|
||||
config.HTTPAccessLog.EnableServerNotFound = true
|
||||
config.HTTPAccessLog.Rotate = NewDefaultAccessLogRotateConfig()
|
||||
|
||||
config.Log.RecordServerError = false
|
||||
|
||||
@@ -79,6 +80,7 @@ type GlobalServerConfig struct {
|
||||
EnableServerNotFound bool `yaml:"enableServerNotFound" json:"enableServerNotFound"` // 记录服务找不到的日志
|
||||
WriteTargets *AccessLogWriteTargets `yaml:"writeTargets" json:"writeTargets"` // 写入目标:文件/MySQL/ClickHouse(双写/单写)
|
||||
FilePath string `yaml:"filePath" json:"filePath"` // 公用日志策略文件路径(用于节点侧复用)
|
||||
Rotate *AccessLogRotateConfig `yaml:"rotate" json:"rotate"` // 本地日志轮转配置(lumberjack)
|
||||
} `yaml:"httpAccessLog" json:"httpAccessLog"` // 访问日志配置
|
||||
|
||||
Stat struct {
|
||||
|
||||
Reference in New Issue
Block a user