tail

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Oct 3, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package tail implements the log file/output tail-ing operations.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Scan

func Scan(ctx context.Context, opts ...OpOption) (int, error)

Scan scans the file or commands output from the end of the file and return the number of matched lines. It returns the lines in the reverse order that evaluates true for the "match" function. If the match function is nil, returns all.

Types

type Line

type Line struct {
	*tail.Line
	MatchedFilter *query_log_filter.Filter
}

type Op

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

type OpOption

type OpOption func(*Op)

func WithCommands

func WithCommands(commands [][]string) OpOption

func WithFile

func WithFile(file string) OpOption

func WithLinesToTail

func WithLinesToTail(n int) OpOption

Sets the number of lines to tail. If not set, defaults to 100.

func WithParseTime

func WithParseTime(f ParseTimeFunc) OpOption

func WithPerLineFunc

func WithPerLineFunc(f func([]byte)) OpOption

Called for each line.

func WithProcessMatched

func WithProcessMatched(f ProcessMatchedFunc) OpOption

Called if the line is matched. If not set, the matched line is no-op. Useful to append to a slice or not to return a string slice to avoid extra heap allocation.

func WithRejectFilter

func WithRejectFilter(filters ...*query_log_filter.Filter) OpOption

"AND" conditions to exclude logs.

The line is sent if and only if all of the filters do not match. Useful for explicit whitelisting logs and catch all other (e.g., good healthy log messages).

func WithSelectFilter

func WithSelectFilter(filters ...*query_log_filter.Filter) OpOption

"OR" conditions to select logs.

The line is sent when any of the filters match. Useful for explicit blacklisting "error" logs (e.g., GPU error messages in dmesg).

type ParseTimeFunc

type ParseTimeFunc func([]byte) (time.Time, error)

type ProcessMatchedFunc

type ProcessMatchedFunc func([]byte, time.Time, *query_log_filter.Filter)

type Streamer

type Streamer interface {
	// Returns the file that the streamer watches on.
	File() string
	// Returns the command arguments that the streamer watches on.
	Commands() [][]string

	// Returns the line channel that the streaming lines are sent to.
	Line() <-chan Line
}

Streamer defines the log tailer.

func NewFromCommand

func NewFromCommand(ctx context.Context, commands [][]string, opts ...OpOption) (Streamer, error)

func NewFromFile

func NewFromFile(file string, seek *tail.SeekInfo, opts ...OpOption) (Streamer, error)

Jump to

Keyboard shortcuts

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