Documentation
¶
Overview ¶
Package tail implements file tailing with fsnotify.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrStop = errors.New("tail should now stop")
ErrStop is returned when the tail of a file has been marked to be stopped.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Location sets starting file location.
Location *Location
// NotifyTimeout enables additional timeout for file changes waiting.
// Can be used to ensure that we never miss event even if newWatcher fails to
// deliver event.
// Optional.
NotifyTimeout time.Duration
// Follow file after reaching io.EOF, waiting for new lines.
Follow bool
// BufferSize for internal reader, optional.
BufferSize int
// Logger to use, optional.
Logger *zap.Logger
// Tracker is optional custom *Tracker.
Tracker *Tracker
}
Config is used to specify how a file must be tailed.
type Handler ¶
Handler is called on each log line.
Implementation should not retain Line or Line.Data.
type Line ¶
type Line struct {
Data []byte // do not retain, reused while reading file
Offset int64 // is always the offset from start
}
Line of file.
type Tailer ¶
type Tailer struct {
// contains filtered or unexported fields
}
Tailer implements file tailing.
Use Tail() to start.
func File ¶
File configures and creates new unstarted *Tailer.
Use Tailer.Tail() to start tailing file.
func (*Tailer) Tail ¶
Tail opens file and starts tailing it, reporting observed lines to Handler.
Tail is blocking while calling Handler to reuse internal buffer and reduce allocations. Tail will call Handler in same sequence as lines are observed. See Handler for more info.
Can be called multiple times, but not concurrently.
type Tracker ¶
type Tracker struct {
// contains filtered or unexported fields
}
Tracker multiplexes fsnotify events.
func NewTracker ¶
NewTracker creates new custom *Tracker with provided logger.
It is recommended to use it as singleton and create only once.