tealogs

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2020 License: MIT, MIT Imports: 32 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DBBatchLogSize = 256
)

导入数据库的访问日志的步长

Variables

View Source
var SyslogStoragePriorities = []maps.Map{
	{
		"name":  "[无]",
		"value": -1,
	},
	{
		"name":  "EMERG",
		"value": SyslogStoragePriorityEmerg,
	},
	{
		"name":  "ALERT",
		"value": SyslogStoragePriorityAlert,
	},
	{
		"name":  "CRIT",
		"value": SyslogStoragePriorityCrit,
	},
	{
		"name":  "ERR",
		"value": SyslogStoragePriorityErr,
	},
	{
		"name":  "WARNING",
		"value": SyslogStoragePriorityWarning,
	},
	{
		"name":  "NOTICE",
		"value": SyslogStoragePriorityNotice,
	},
	{
		"name":  "INFO",
		"value": SyslogStoragePriorityInfo,
	},
	{
		"name":  "DEBUG",
		"value": SyslogStoragePriorityDebug,
	},
}

Functions

func AddAccessLogHook

func AddAccessLogHook(hook *AccessLogHook)

添加Hook

func AllStorageFormats

func AllStorageFormats() []maps.Map

所有存储的格式

func AllStorages

func AllStorages() []maps.Map

所有存储引擎列表

func CallAccessLogHooks

func CallAccessLogHooks(accessLog *accesslogs.AccessLog)

执行Filter

func FindPolicy

func FindPolicy(policyId string) *teaconfigs.AccessLogStoragePolicy

通过策略ID查找策略

func FindPolicyName

func FindPolicyName(policyId string) string

查找策略名称

func FindStorageFormatName

func FindStorageFormatName(code string) string

根据代号查找名称

func FindStorageTypeName

func FindStorageTypeName(storageType string) string

根据类型查找名称

func ResetAllPolicies

func ResetAllPolicies()

清除所有策略相关信息

func ResetPolicyStorage

func ResetPolicyStorage(policyId string)

清除策略相关信息

Types

type AccessLogHook

type AccessLogHook struct {
	Process func(accessLog *accesslogs.AccessLog) (goNext bool)
}

请求Hook定义

type AccessLogQueue

type AccessLogQueue struct {
	// contains filtered or unexported fields
}

访问日志队列

func NewAccessLogQueue

func NewAccessLogQueue(buffer *logbuffer.Buffer, index int) *AccessLogQueue

创建队列对象

func (*AccessLogQueue) Dump

func (this *AccessLogQueue) Dump()

导出日志到别的媒介

func (*AccessLogQueue) Receive

func (this *AccessLogQueue) Receive(ch chan *accesslogs.AccessLog)

从队列中接收日志

type AccessLogger

type AccessLogger struct {
	// contains filtered or unexported fields
}

访问日志记录器

func NewAccessLogger

func NewAccessLogger() *AccessLogger

获取新日志对象

func SharedLogger

func SharedLogger() *AccessLogger

获取共享的对象

func (*AccessLogger) Push

func (this *AccessLogger) Push(log *accesslogs.AccessLog)

推送日志

type CommandStorage

type CommandStorage struct {
	Storage `yaml:", inline"`

	Command string   `yaml:"command" json:"command"`
	Args    []string `yaml:"args" json:"args"`
	Dir     string   `yaml:"dir" json:"dir"`
	// contains filtered or unexported fields
}

通过命令行存储

func (*CommandStorage) Close

func (this *CommandStorage) Close() error

关闭

func (*CommandStorage) Start

func (this *CommandStorage) Start() error

启动

func (*CommandStorage) Write

func (this *CommandStorage) Write(accessLogs []*accesslogs.AccessLog) error

写入日志

type ESStorage

type ESStorage struct {
	Storage `yaml:", inline"`

	Endpoint    string `yaml:"endpoint" json:"endpoint"`
	Index       string `yaml:"index" json:"index"`
	MappingType string `yaml:"mappingType" json:"mappingType"`
	Username    string `yaml:"username" json:"username"`
	Password    string `yaml:"password" json:"password"`
}

ElasticSearch存储策略

func (*ESStorage) Close

func (this *ESStorage) Close() error

关闭

func (*ESStorage) Start

func (this *ESStorage) Start() error

开启

func (*ESStorage) Write

func (this *ESStorage) Write(accessLogs []*accesslogs.AccessLog) error

写入日志

type FileStorage

type FileStorage struct {
	Storage `yaml:", inline"`

	Path       string `yaml:"path" json:"path"`             // 文件路径,支持变量:${year|month|week|day|hour|minute|second}
	AutoCreate bool   `yaml:"autoCreate" json:"autoCreate"` // 是否自动创建目录
	// contains filtered or unexported fields
}

文件存储策略

func (*FileStorage) Close

func (this *FileStorage) Close() error

关闭

func (*FileStorage) Start

func (this *FileStorage) Start() error

开启

func (*FileStorage) Write

func (this *FileStorage) Write(accessLogs []*accesslogs.AccessLog) error

写入日志

type MySQLStorage

type MySQLStorage struct {
	Storage `yaml:", inline"`

	Host            string `yaml:"host" json:"host"`
	Port            int    `yaml:"port" json:"port"`
	Username        string `yaml:"username" json:"username"`
	Password        string `yaml:"password" json:"password"`
	Database        string `yaml:"database" json:"database"`
	Table           string `yaml:"table" json:"table"` // can use variables, such as ${year}
	LogField        string `yaml:"logField" json:"logField"`
	AutoCreateTable bool   `yaml:"autoCreateTable" json:"autoCreateTable"`
}

MySQL存储

func (*MySQLStorage) Close

func (this *MySQLStorage) Close() error

关闭

func (*MySQLStorage) Start

func (this *MySQLStorage) Start() error

启动

func (*MySQLStorage) Write

func (this *MySQLStorage) Write(accessLogs []*accesslogs.AccessLog) error

写入日志

type Storage

type Storage struct {
	Format   StorageFormat `yaml:"format" json:"format"`     // 日志格式
	Template string        `yaml:"template" json:"template"` // 只有在Format为template时有效
}

基础的Storage

func (*Storage) FormatAccessLogBytes

func (this *Storage) FormatAccessLogBytes(accessLog *accesslogs.AccessLog) ([]byte, error)

格式化访问日志成字节

func (*Storage) FormatAccessLogString

func (this *Storage) FormatAccessLogString(accessLog *accesslogs.AccessLog) (string, error)

格式化访问日志成字符串

func (*Storage) FormatVariables

func (this *Storage) FormatVariables(s string) string

格式化字符串中的变量

type StorageFormat

type StorageFormat = string

存储日志的格式

const (
	StorageFormatJSON     StorageFormat = "json"
	StorageFormatTemplate StorageFormat = "template"
)

type StorageInterface

type StorageInterface interface {
	// 开启
	Start() error

	// 写入日志
	Write(accessLogs []*accesslogs.AccessLog) error

	// 关闭
	Close() error
}

日志存储接口

func DecodePolicyStorage

func DecodePolicyStorage(policy *teaconfigs.AccessLogStoragePolicy) StorageInterface

解析策略中的存储对象

func FindPolicyStorage

func FindPolicyStorage(policyId string) StorageInterface

通过策略ID查找存储

type StorageType

type StorageType = string

存储引擎类型

const (
	StorageTypeFile    StorageType = "file"
	StorageTypeES      StorageType = "es"
	StorageTypeMySQL   StorageType = "mysql"
	StorageTypeTCP     StorageType = "tcp"
	StorageTypeSyslog  StorageType = "syslog"
	StorageTypeCommand StorageType = "command"
)

type SyslogStorage

type SyslogStorage struct {
	Storage `yaml:", inline"`

	Protocol   string                `yaml:"protocol" json:"protocol"` // SysLogStorageProtocol*
	ServerAddr string                `yaml:"serverAddr" json:"serverAddr"`
	ServerPort int                   `yaml:"serverPort" json:"serverPort"`
	Socket     string                `yaml:"socket" json:"socket"` // sock file
	Tag        string                `yaml:"tag" json:"tag"`
	Priority   SyslogStoragePriority `yaml:"priority" json:"priority"`
	// contains filtered or unexported fields
}

syslog存储策略

func (*SyslogStorage) Close

func (this *SyslogStorage) Close() error

关闭

func (*SyslogStorage) Start

func (this *SyslogStorage) Start() error

开启

func (*SyslogStorage) Write

func (this *SyslogStorage) Write(accessLogs []*accesslogs.AccessLog) error

写入日志

type SyslogStoragePriority

type SyslogStoragePriority = int
const (
	SyslogStoragePriorityEmerg SyslogStoragePriority = iota
	SyslogStoragePriorityAlert
	SyslogStoragePriorityCrit
	SyslogStoragePriorityErr
	SyslogStoragePriorityWarning
	SyslogStoragePriorityNotice
	SyslogStoragePriorityInfo
	SyslogStoragePriorityDebug
)

type SyslogStorageProtocol

type SyslogStorageProtocol = string
const (
	SyslogStorageProtocolTCP    SyslogStorageProtocol = "tcp"
	SyslogStorageProtocolUDP    SyslogStorageProtocol = "udp"
	SyslogStorageProtocolNone   SyslogStorageProtocol = "none"
	SyslogStorageProtocolSocket SyslogStorageProtocol = "socket"
)

type TCPStorage

type TCPStorage struct {
	Storage `yaml:", inline"`

	Network string `yaml:"network" json:"network"` // tcp, unix
	Addr    string `yaml:"addr" json:"addr"`
	// contains filtered or unexported fields
}

TCP存储策略

func (*TCPStorage) Close

func (this *TCPStorage) Close() error

关闭

func (*TCPStorage) Start

func (this *TCPStorage) Start() error

开启

func (*TCPStorage) Write

func (this *TCPStorage) Write(accessLogs []*accesslogs.AccessLog) error

写入日志

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL