diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..0514452b --- /dev/null +++ b/go.mod @@ -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 +) diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..c95ba6dd --- /dev/null +++ b/go.sum @@ -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= diff --git a/tail.go b/tail.go index 67329966..f3cc5d3d 100644 --- a/tail.go +++ b/tail.go @@ -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) @@ -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() }