tail

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: Apache-2.0 Imports: 12 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_common.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 WithDedup added in v0.1.6

func WithDedup(dedup bool) OpOption

If true, dedup lines by the log line string. This is useful for logs that have the same message repeated multiple times with the same timestamp.

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 WithPerLineFunc

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

Called for each line.

func WithProcessMatched

func WithProcessMatched(f query_log_common.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_common.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_common.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 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