Files
EdgeCommon/pkg/serverconfigs/http_access_log_ref.go

93 lines
2.2 KiB
Go
Raw Normal View History

2020-09-20 11:56:22 +08:00
package serverconfigs
2021-05-06 19:47:37 +08:00
// DefaultHTTPAccessLogRef 默认的访问日志配置
2020-10-10 11:49:30 +08:00
var DefaultHTTPAccessLogRef = NewHTTPAccessLogRef()
2021-05-06 19:47:37 +08:00
// HTTPAccessLogRef 代理访问日志配置
2020-09-20 16:27:59 +08:00
type HTTPAccessLogRef struct {
2020-09-23 18:43:50 +08:00
IsPrior bool `yaml:"isPrior" json:"isPrior"` // 是否覆盖
IsOn bool `yaml:"isOn" json:"isOn"` // 是否启用
2020-09-20 11:56:22 +08:00
Fields []int `yaml:"fields" json:"fields"` // 记录的字段
Status1 bool `yaml:"status1" json:"status1"` // 1xx
Status2 bool `yaml:"status2" json:"status2"` // 2xx
Status3 bool `yaml:"status3" json:"status3"` // 3xx
Status4 bool `yaml:"status4" json:"status4"` // 4xx
Status5 bool `yaml:"status5" json:"status5"` // 5xx
2021-12-01 21:14:07 +08:00
EnableClientClosed bool `yaml:"enableClientClosed" json:"enableClientClosed"` // 是否记录客户端关闭事件
2020-09-20 11:56:22 +08:00
StorageOnly bool `yaml:"storageOnly" json:"storageOnly"` // 是否只输出到存储策略
StoragePolicies []int64 `yaml:"storagePolicies" json:"storagePolicies"` // 存储策略Ids
FirewallOnly bool `yaml:"firewallOnly" json:"firewallOnly"` // 是否只记录防火墙相关日志
2020-09-20 11:56:22 +08:00
}
2021-05-06 19:47:37 +08:00
// NewHTTPAccessLogRef 获取新对象
2020-09-20 16:27:59 +08:00
func NewHTTPAccessLogRef() *HTTPAccessLogRef {
return &HTTPAccessLogRef{
2021-05-06 19:47:37 +08:00
IsOn: false,
2020-09-20 11:56:22 +08:00
Fields: []int{},
Status1: true,
Status2: true,
Status3: true,
Status4: true,
Status5: true,
}
}
2021-05-06 19:47:37 +08:00
// Init 校验
2020-09-20 16:27:59 +08:00
func (this *HTTPAccessLogRef) Init() error {
2020-09-20 11:56:22 +08:00
return nil
}
2021-05-06 19:47:37 +08:00
// Match 判断是否应该记录
2020-09-20 16:27:59 +08:00
func (this *HTTPAccessLogRef) Match(status int) bool {
2020-09-20 11:56:22 +08:00
s := status / 100
switch s {
case 1:
if !this.Status1 {
return false
}
case 2:
if !this.Status2 {
return false
}
case 3:
if !this.Status3 {
return false
}
case 4:
if !this.Status4 {
return false
}
case 5:
if !this.Status5 {
return false
}
}
return true
}
2021-05-06 19:47:37 +08:00
// ContainsStoragePolicy 是否包含某个存储策略
2020-09-20 16:27:59 +08:00
func (this *HTTPAccessLogRef) ContainsStoragePolicy(storagePolicyId int64) bool {
2020-09-20 11:56:22 +08:00
for _, s := range this.StoragePolicies {
if s == storagePolicyId {
return true
}
}
return false
}
2020-10-10 11:49:30 +08:00
2021-05-06 19:47:37 +08:00
// ContainsField 检查是否包含某个Field
2020-10-10 11:49:30 +08:00
func (this *HTTPAccessLogRef) ContainsField(field int) bool {
for _, f := range this.Fields {
if f == field {
return true
}
}
return false
}