Documentation
¶
Index ¶
- Variables
- func MakeReopenLogCh() chan struct{}
- func MakeShutdownCh() chan struct{}
- func NewLogCommandBuilder() *logCommandBuilder
- func StartLogCollectors(ctx context.Context, collectors []*OSLogCollector)
- type Agent
- type Config
- type LogCommandRunner
- type LogCommandRunnerGenerator
- type OSLogCollector
- type OSLogCollectorConfig
- type OSLogCollectorOption
- type Position
Constants ¶
This section is empty.
Variables ¶
var (
LogCommandTimeFormat = "2006-01-02 15:04:05"
)
Functions ¶
func MakeReopenLogCh ¶
func MakeReopenLogCh() chan struct{}
MakeReopenLogCh creates a channel that will receive a value when the process receives a SIGUSR1 signal. Some log rotate tools like newsyslog do not support copytruncate, so the old log file remains open. When receiving the USR1 signal (30), reopen log collector's log file to handle this.
func MakeShutdownCh ¶
func MakeShutdownCh() chan struct{}
MakeShutdownCh creates a channel that will be closed when the process receives a SIGINT or SIGTERM signal.
func NewLogCommandBuilder ¶
func NewLogCommandBuilder() *logCommandBuilder
func StartLogCollectors ¶
func StartLogCollectors(ctx context.Context, collectors []*OSLogCollector)
StartLogCollectors starts the OS Log collectors in the background. It will run until the context is canceled.
Types ¶
type Agent ¶
type Agent struct {
Config *Config
LogCollectors []*OSLogCollector
ReopenLogCh chan struct{}
ShutdownCh chan struct{}
}
func NewAgentFromConfigFile ¶
type Config ¶
type Config struct {
// Collectors is a list of OS Log collectors
Collectors []OSLogCollectorConfig `yaml:"collectors"`
// PIDFile is the file to write the process ID to
PIDFile string `yaml:"pid_file"`
}
func LoadConfigFromFile ¶
func ParseConfig ¶
type LogCommandRunner ¶
func NewLogCommandRunner ¶
func NewLogCommandRunner(args []string) LogCommandRunner
type LogCommandRunnerGenerator ¶
type LogCommandRunnerGenerator func(args []string) LogCommandRunner
type OSLogCollector ¶
type OSLogCollector struct {
Name string
Predicate string
OutputFile string
PositionFile string
Interval int
LastTimestamp string
WithInfoLevel bool
// contains filtered or unexported fields
}
func NewOSLogCollector ¶
func NewOSLogCollector(config OSLogCollectorConfig, opts ...OSLogCollectorOption) (*OSLogCollector, error)
func (*OSLogCollector) CollectLogs ¶
func (c *OSLogCollector) CollectLogs() error
func (*OSLogCollector) OpenLogFile ¶
func (c *OSLogCollector) OpenLogFile() error
type OSLogCollectorConfig ¶
type OSLogCollectorConfig struct {
// Name is the name of the collector
Name string `yaml:"name"`
// Predicate is the condition to get logs, which is a string passed to the --predicate option of the log command
Predicate string `yaml:"predicate"`
// OutputFile is the file to write the logs to
OutputFile string `yaml:"output_file"`
// PositionFile is the file to record the collection position of the logs
// If this file exists, logs are collected from the position recorded in this file.
PositionFile string `yaml:"position_file"`
// Interval is the interval to collect logs in seconds
Interval int `yaml:"interval"`
// WithInfoLevel is a flag to enable the --info option of the log command
WithInfoLevel bool `yaml:"with_info_level"`
}
type OSLogCollectorOption ¶
type OSLogCollectorOption func(*OSLogCollector)
func WithLogCommandRunner ¶
func WithLogCommandRunner(generator LogCommandRunnerGenerator) OSLogCollectorOption