file

package
v0.0.0-...-cdf0a0a Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2024 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

type File struct {
	// Path contains the path to the file which should be tailed.
	Path string

	// IsWildcardPath is set to true when the File has been discovered
	// in a directory with wildcard(s) in the configuration.
	IsWildcardPath bool

	// Source is the ReplaceableSource that led to this File.
	Source *sources.ReplaceableSource
}

File represents a file to tail

func NewFile

func NewFile(path string, source *sources.LogSource, isWildcardPath bool) *File

NewFile returns a new File

func (*File) GetScanKey

func (t *File) GetScanKey() string

GetScanKey returns a key used by the scanner to index the scanned file. The string uniquely identifies this File, even if sources for multiple containers use the same Path.

type Tailer

type Tailer struct {
	PipelineMonitor metrics.PipelineMonitor
	// contains filtered or unexported fields
}

Tailer tails a file, decodes the messages it contains, and passes them to a supplied output channel for further processing.

Operational Overview

Tailers have three components, organized as a pipeline. The first, readForever, polls the file, trying to read more data. That data is passed to the second component, the decoder. The decoder produces decoder.Messages, which are passed to the third component, forwardMessages. This component translates the decoder.Messages into message.Messages and sends them to the tailer's output channel.

func NewTailer

func NewTailer(opts *TailerOptions) *Tailer

NewTailer returns an initialized Tailer, read to be started.

The resulting Tailer will read from the given `file`, decode the content with the given `decoder`, and send the resulting log messages to outputChan. The Tailer takes ownership of the decoder and will start and stop it as necessary.

The Tailer must poll for content in the file. The `sleepDuration` parameter specifies how long the tailer should wait between polls.

func (*Tailer) DidRotate

func (t *Tailer) DidRotate() (bool, error)

DidRotate returns true if the file has been log-rotated.

On *nix, when a log rotation occurs, the file can be either: - renamed and recreated - removed and recreated - truncated

func (*Tailer) GetDetectedPattern

func (t *Tailer) GetDetectedPattern() *regexp.Regexp

GetDetectedPattern returns the decoder's detected pattern.

func (*Tailer) GetId

func (t *Tailer) GetId() string

func (*Tailer) GetInfo

func (t *Tailer) GetInfo() *status.InfoRegistry

func (*Tailer) GetType

func (t *Tailer) GetType() string

func (*Tailer) Identifier

func (t *Tailer) Identifier() string

Identifier returns a string that identifies this tailer in the registry.

func (*Tailer) IsFinished

func (t *Tailer) IsFinished() bool

IsFinished returns true if the tailer has flushed all messages to the output channel, either because it has been stopped or because of an error reading from the input file.

func (*Tailer) NewRotatedTailer

func (t *Tailer) NewRotatedTailer(file *File, outputChan chan *message.Message, pipelineMonitor metrics.PipelineMonitor, decoder *decoder.Decoder, info *status.InfoRegistry, tagAdder tag.EntityTagAdder) *Tailer

NewRotatedTailer creates a new tailer that replaces this one, writing messages to a new channel and using an updated file and decoder.

func (*Tailer) ReplaceSource

func (t *Tailer) ReplaceSource(newSource *sources.LogSource)

ReplaceSource replaces the current source

func (*Tailer) Source

func (t *Tailer) Source() *sources.LogSource

Source gets the source (currently only used for testing)

func (*Tailer) Start

func (t *Tailer) Start(offset int64, whence int) error

Start begins the tailer's operation in a dedicated goroutine.

func (*Tailer) StartFromBeginning

func (t *Tailer) StartFromBeginning() error

StartFromBeginning is a shortcut to start the tailer at the beginning of the file.

func (*Tailer) Stop

func (t *Tailer) Stop()

Stop stops the tailer and returns only after all in-flight messages have been flushed to the output channel.

func (*Tailer) StopAfterFileRotation

func (t *Tailer) StopAfterFileRotation()

StopAfterFileRotation prepares the tailer to stop after a timeout to finish reading its file that has been log-rotated

type TailerOptions

type TailerOptions struct {
	OutputChan      chan *message.Message   // Required
	File            *File                   // Required
	SleepDuration   time.Duration           // Required
	Decoder         *decoder.Decoder        // Required
	Info            *status.InfoRegistry    // Required
	Rotated         bool                    // Optional
	TagAdder        tag.EntityTagAdder      // Required
	PipelineMonitor metrics.PipelineMonitor // Required
}

TailerOptions holds all possible parameters that NewTailer requires in addition to optional parameters that can be optionally passed into. This can be used for more optional parameters if required in future

Jump to

Keyboard shortcuts

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