Skip to content

Commit

Permalink
#5 prepare linux file tailer for multiple log file support
Browse files Browse the repository at this point in the history
  • Loading branch information
fstab committed Jan 22, 2019
1 parent 64d41ad commit 2512da1
Show file tree
Hide file tree
Showing 16 changed files with 951 additions and 511 deletions.
17 changes: 6 additions & 11 deletions tailer/fileTailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package tailer

import (
"fmt"
"github.com/sirupsen/logrus"
"io"
"os"
"path/filepath"
Expand Down Expand Up @@ -44,16 +45,18 @@ func (f *fileTailer) Errors() chan Error {
return f.errors
}

func RunPollingFileTailer(path string, readall bool, failOnMissingFile bool, pollIntervall time.Duration, logger simpleLogger) Tailer {
func RunPollingFileTailer(path string, readall bool, failOnMissingFile bool, pollIntervall time.Duration, logger logrus.FieldLogger) Tailer {
makeWatcher := func(abspath string, _ *File) (Watcher, error) {
return NewPollingWatcher(abspath, pollIntervall)
}
return runFileTailer(path, readall, failOnMissingFile, logger, makeWatcher)
}

func runFileTailer(path string, readall bool, failOnMissingFile bool, logger simpleLogger, makeWatcher func(string, *File) (Watcher, error)) Tailer {
func runFileTailer(path string, readall bool, failOnMissingFile bool, logger logrus.FieldLogger, makeWatcher func(string, *File) (Watcher, error)) Tailer {
if logger == nil {
logger = &nilLogger{}
log := logrus.New()
log.Level = logrus.WarnLevel
logger = log
}

lines := make(chan string)
Expand Down Expand Up @@ -199,11 +202,3 @@ func writeError(errors chan Error, done chan struct{}, cause error, format strin
case <-done:
}
}

type simpleLogger interface {
Debug(format string, a ...interface{})
}

type nilLogger struct{}

func (_ *nilLogger) Debug(_ string, _ ...interface{}) {}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !darwin
// +build !darwin,!linux

package tailer

import "github.com/sirupsen/logrus"

// old implementation, darwin is already switched to the new implementation, the other OSes will follow
func RunFseventFileTailer(path string, readall bool, failOnMissingFile bool, logger simpleLogger) Tailer {
func RunFseventFileTailer(path string, readall bool, failOnMissingFile bool, logger logrus.FieldLogger) Tailer {
return runFileTailer(path, readall, failOnMissingFile, logger, NewFseventWatcher)
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ package tailer

import (
"github.com/fstab/grok_exporter/tailer/fswatcher"
"github.com/fstab/grok_exporter/tailer/glob"
"github.com/sirupsen/logrus"
)

// TODO: This wrapper will be removed when all OSs are migrated to the new fswatcher, supporting multiple log files.

type tailerWrapper struct {
lines chan string
errors chan Error
Expand All @@ -38,14 +42,21 @@ func (t *tailerWrapper) Errors() chan Error {

// Switch to the new file tailer implementation which supports watching multiple files.
// Once we switched for all supported operating systems, we can remove the old implementation and the wrapper.
func RunFseventFileTailer(path string, readall bool, failOnMissingFile bool, _ interface{}) Tailer {
func RunFseventFileTailer(path string, readall bool, failOnMissingFile bool, logger logrus.FieldLogger) Tailer {
result := &tailerWrapper{
lines: make(chan string),
errors: make(chan Error),
done: make(chan struct{}),
}

newTailer, err := fswatcher.Run([]string{path}, readall, failOnMissingFile)
pathAsGlob, err := glob.Parse(path)
if err != nil {
go func() {
result.errors <- newError("failed to initialize file system watcher", err)
}()
return result
}
newTailer, err := fswatcher.Run([]glob.Glob{pathAsGlob}, readall, failOnMissingFile, logger)
if err != nil {
go func() {
result.errors <- newError("failed to initialize file system watcher", err)
Expand Down
272 changes: 0 additions & 272 deletions tailer/fileTailer_linux.go

This file was deleted.

Loading

0 comments on commit 2512da1

Please sign in to comment.