Documentation ¶
Index ¶
- Constants
- Variables
- func DidRotate(file *os.File, lastReadOffset int64) (bool, error)
- func NewDecoderFromSource(source *logsconfig.LogSource) *decoder.Decoder
- func NewDecoderFromSourceWithPattern(source *logsconfig.LogSource, multiLinePattern *regexp.Regexp) *decoder.Decoder
- func Position(registry auditor.Registry, identifier string, mode logsconfig.TailingMode) (int64, int, error)
- type File
- type Provider
- type Scanner
- type Tailer
- func (t *Tailer) GetDetectedPattern() *regexp.Regexp
- func (t *Tailer) GetReadOffset() int64
- func (t *Tailer) Identifier() string
- func (t *Tailer) SetDecodedOffset(off int64)
- func (t *Tailer) SetReadOffset(off int64)
- func (t *Tailer) Start(offset int64, whence int) error
- func (t *Tailer) StartFromBeginning() error
- func (t *Tailer) Stop()
- func (t *Tailer) StopAfterFileRotation()
Constants ¶
const DefaultSleepDuration = 1 * time.Second
DefaultSleepDuration represents the amount of time the tailer waits before reading new data when no data is received
Variables ¶
var ContainersLogsDir = "/var/log/containers"
ContainersLogsDir is the directory in which we should find containers logsfile with the container ID in their filename. Public to be able to change it while running unit tests.
Functions ¶
func DidRotate ¶
DidRotate returns true if the file has been log-rotated. When a log rotation occurs, the file can be either: - renamed and recreated - removed and recreated - truncated
func NewDecoderFromSource ¶
func NewDecoderFromSource(source *logsconfig.LogSource) *decoder.Decoder
NewDecoderFromSource creates a new decoder from a log source
func NewDecoderFromSourceWithPattern ¶
func NewDecoderFromSourceWithPattern(source *logsconfig.LogSource, multiLinePattern *regexp.Regexp) *decoder.Decoder
NewDecoderFromSourceWithPattern creates a new decoder from a log source with a multiline pattern
func Position ¶
func Position(registry auditor.Registry, identifier string, mode logsconfig.TailingMode) (int64, int, error)
Position returns the position from where logs should be collected.
Types ¶
type File ¶
type File struct { 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 *logsconfig.LogSource }
File represents a file to tail
func NewFile ¶
func NewFile(path string, source *logsconfig.LogSource, isWildcardPath bool) *File
NewFile returns a new File
func (*File) GetScanKey ¶
GetScanKey returns a key used by the scanner to index the scanned file. If it is a file scanned for a container, it will use the format: <filepath>/<container_id> Otherwise, it will simply use the format: <filepath>
type Provider ¶
type Provider struct {
// contains filtered or unexported fields
}
Provider implements the logic to retrieve at most filesLimit Files defined in sources
func (*Provider) CollectFiles ¶
func (p *Provider) CollectFiles(source *logsconfig.LogSource) ([]*File, error)
CollectFiles returns all the files matching the source path.
func (*Provider) FilesToTail ¶
func (p *Provider) FilesToTail(sources []*logsconfig.LogSource) []*File
FilesToTail returns all the Files matching paths in sources, it cannot return more than filesLimit Files. For now, there is no way to prioritize specific Files over others, they are just returned in reverse lexicographical order, see `searchFiles`
type Scanner ¶
type Scanner struct {
// contains filtered or unexported fields
}
Scanner checks all files provided by fileProvider and create new tailers or update the old ones if needed
func NewScanner ¶
func NewScanner(sources *logsconfig.LogSources, tailingLimit int, pipelineProvider pipeline.Provider, registry auditor.Registry, tailerSleepDuration time.Duration, validatePodContainerID bool, scanPeriod time.Duration) *Scanner
NewScanner returns a new scanner.
type Tailer ¶
type Tailer struct {
// contains filtered or unexported fields
}
Tailer tails one file and sends messages to an output channel
func NewTailer ¶
func NewTailer(outputChan chan *message.Message, file *File, sleepDuration time.Duration, decoder *decoder.Decoder) *Tailer
NewTailer returns an initialized Tailer
func (*Tailer) GetDetectedPattern ¶
GetDetectedPattern returns a regexp if a pattern was detected
func (*Tailer) GetReadOffset ¶
GetReadOffset returns the position of the last byte read in file
func (*Tailer) Identifier ¶
Identifier returns a string that uniquely identifies a source. This is the identifier used in the registry. FIXME(remy): during container rotation, this Identifier() method could return the same value for different tailers. It is happening during container rotation where the dead container still has a tailer running on the log file, and the tailer of the freshly spawned container starts tailing this file as well.
func (*Tailer) SetDecodedOffset ¶
SetDecodedOffset sets the position of the last byte decoded in the file
func (*Tailer) SetReadOffset ¶
SetReadOffset sets the position of the last byte read in the file
func (*Tailer) StartFromBeginning ¶
StartFromBeginning lets the tailer start tailing its file from the beginning
func (*Tailer) Stop ¶
func (t *Tailer) Stop()
Stop stops the tailer and returns only when the decoder is flushed
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