Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/influxdata/tail

go 1.13

require (
gopkg.in/fsnotify.v1 v1.2.1
gopkg.in/tomb.v1 v1.0.0-20140529071818-c131134a1947
)
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/influxdata/tail v1.0.0 h1:RGikfjB/b5C/YP3p47YD48eE0WSsJyAVbBHNpoTHdX0=
github.com/influxdata/tail v1.0.0/go.mod h1:xTFF2SILpIYc5N+Srb0d5qpx7d+f733nBrbasb13DtQ=
gopkg.in/fsnotify.v1 v1.2.1 h1:x2hwAFVlj5ptNfCIgr3KRZm9IQcKDCWJbQDO7QxUXOo=
gopkg.in/fsnotify.v1 v1.2.1/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20140529071818-c131134a1947 h1:aNEcl02ps/eZaBJi2LycKl0jPsUryySSSgrCxieZRYA=
gopkg.in/tomb.v1 v1.0.0-20140529071818-c131134a1947/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
22 changes: 14 additions & 8 deletions tail.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,13 @@ type logger interface {
// Config is used to specify how a file must be tailed.
type Config struct {
// File-specifc
Location *SeekInfo // Seek to this location before tailing
ReOpen bool // Reopen recreated files (tail -F)
MustExist bool // Fail early if the file does not exist
Poll bool // Poll for file changes instead of using inotify
Pipe bool // Is a named pipe (mkfifo)
RateLimiter *ratelimiter.LeakyBucket
Location *SeekInfo // Seek to this location before tailing
ReOpen bool // Reopen recreated files (tail -F)
MustExist bool // Fail early if the file does not exist
Poll bool // Poll for file changes instead of using inotify
Pipe bool // Is a named pipe (mkfifo)
RateLimiter *ratelimiter.LeakyBucket
OpenReaderFunc func(rd io.Reader) io.Reader

// Generic IO
Follow bool // Continue looking for new lines (tail -f)
Expand Down Expand Up @@ -396,11 +397,16 @@ func (tail *Tail) waitForChanges() error {

func (tail *Tail) openReader() {
tail.lk.Lock()
var rd io.Reader = tail.file
if tail.OpenReaderFunc != nil {
rd = tail.OpenReaderFunc(rd)
}

if tail.MaxLineSize > 0 {
// add 2 to account for newline characters
tail.reader = bufio.NewReaderSize(tail.file, tail.MaxLineSize+2)
tail.reader = bufio.NewReaderSize(rd, tail.MaxLineSize+2)
} else {
tail.reader = bufio.NewReader(tail.file)
tail.reader = bufio.NewReader(rd)
}
tail.lk.Unlock()
}
Expand Down