logfilter

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2020 License: MIT Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const RFC3339Milli = "2006-01-02T15:04:05.999Z07:00"

Variables

This section is empty.

Functions

func NewDebugServer

func NewDebugServer() *http.Server

Types

type Cmd

type Cmd []string

func (*Cmd) Decode

func (c *Cmd) Decode(value string) error

type Commander

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

Commander starts the command. It handles graceful shutdown with a timeout after which the command is forcefully killed.

func NewCommander

func NewCommander(
	cmd []string,
	cmdShutdownTimeout time.Duration,
	stdout io.Writer,
	stderr io.Writer,
	logger *logrus.Entry,
) *Commander

func (*Commander) Start

func (c *Commander) Start(ctx context.Context) error

type Config

type Config struct {
	// Cmd is the command that logfilter will run and use as the input. If empty
	// process args will be used as the command. If that is empty stdin will be
	// used as the input. Arguments are separated using spaces and can be quoted.
	// (LOGFILTER_CMD)
	Cmd Cmd

	// CmdShutdownTimeout is the timeout after which the command will be
	// forecefully killed after the logfilter is stopped. Command will first
	// receive SIGINT and then SIGKILL after CmdShutdownTimeout.
	// (LOGFILTER_CMDSHUTDOWNTIMEOUT)
	CmdShutdownTimeout time.Duration `default:"10s"`

	// ExcludeTemplate is a Go text/template. If it renders a value "true" the
	// following JSON will be excluded from the stdout. The template can render
	// multiple "true" values to simplify the exclusion logic.
	// (LOGFILTER_EXCLUDETEMPLATE)
	ExcludeTemplate string

	// FilterQuery is a JQ query. You can use `select(.k1 != "v1") | select(.k2 !=
	// "v2")` to filter the JSON lines.
	// (LOGFILTER_FILTER_QUERY)
	FilterQuery string

	// DebugListenAddr is the address of the HTTP debug (pprof) server
	// (LOGFILTER_DEBUGLISTENADDR).
	DebugListenAddr string `default:"localhost:4083"`

	// FullOutputFilename is file to write the full logs to. Backup log files will
	// be retained in the same directory. If empty the full output will be
	// discarded.
	// (LOGFILTER_FULLOUTPUTFILENAME)
	FullOutputFilename string

	// FullOutputMaxSizeMB is the maximum size in megabytes of the log file
	// before it gets rotated. It defaults to 100 megabytes.
	// (LOGFILTER_FULLOUTPUTMAXSIZEMB)
	FullOutputMaxSizeMB int `default:"100"`

	// FullOutputMaxAgeDays is the maximum number of days to retain old log
	// files based on the timestamp encoded in their filename.  Note that a day is
	// defined as 24 hours and may not exactly correspond to calendar days due to
	// daylight savings, leap seconds, etc. The default is not to remove old log
	// files based on age.
	// (LOGFILTER_FULLOUTPUTMAXAGEDAYS)
	FullOutputMaxAgeDays int

	// FullOutputMaxBackups is the maximum number of old log files to retain.
	// The default is to retain all old log files (though FullOutputMaxAgeDays
	// may still cause them to get deleted.)
	// (LOGFILTER_FULLOUTPUTMAXBACKUPS)
	FullOutputMaxBackups int

	// FullOutputCompress determines if the rotated log files should be
	// compressed using gzip. The default is not to perform compression.
	// (LOGFILTER_FULLOUTPUTCOMPRESS)
	FullOutputCompress bool

	// MaxScanLineSize is the maximum size used to buffer lines.
	// (LOGFILTER_MAXSCANLINESIZE)
	MaxScanLineSize int `default:"52428800"`

	// LogLevel is the log level of the logfilter.
	// (LOGFILTER_LOGLEVEL)
	LogLevel string `default:"info"`
}

Config contains the configuration for the logfilter

type JQJSONFilter added in v0.2.0

type JQJSONFilter struct {
	Code *gojq.Code
}

func NewJQJSONFilter added in v0.2.0

func NewJQJSONFilter(queryStr string) (*JQJSONFilter, error)

func (*JQJSONFilter) IsIncluded added in v0.2.0

func (f *JQJSONFilter) IsIncluded(b []byte) (bool, error)

type JSONFilter

type JSONFilter interface {
	IsIncluded(b []byte) (bool, error)
}

type JSONFormatter

type JSONFormatter struct {
	*logrus.JSONFormatter
}

func (*JSONFormatter) Format

func (f *JSONFormatter) Format(entry *logrus.Entry) ([]byte, error)

type LogFilter

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

func NewLogFilter

func NewLogFilter(
	config *Config,
	reader io.Reader,
	writer io.Writer,
	logger *logrus.Entry,
) *LogFilter

func (*LogFilter) Close

func (f *LogFilter) Close() error

func (*LogFilter) Init

func (f *LogFilter) Init(ctx context.Context) error

func (*LogFilter) Spawn

func (f *LogFilter) Spawn(fn func(context.Context) error)

func (*LogFilter) Start

func (f *LogFilter) Start() error

type StaticJSONFilter added in v0.2.0

type StaticJSONFilter bool

func (StaticJSONFilter) IsIncluded added in v0.2.0

func (f StaticJSONFilter) IsIncluded(b []byte) (bool, error)

type TemplateJSONFilter added in v0.2.0

type TemplateJSONFilter struct {
	ExcludeTpl *template.Template
	Buf        bytes.Buffer
}

func NewTemplateJSONFilter added in v0.2.0

func NewTemplateJSONFilter(excludeTemplate string) (*TemplateJSONFilter, error)

func (*TemplateJSONFilter) IsIncluded added in v0.2.0

func (f *TemplateJSONFilter) IsIncluded(b []byte) (bool, error)

Jump to

Keyboard shortcuts

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