Skip to content

Commit

Permalink
#5 prepare macOS file tailer for multiple log file support
Browse files Browse the repository at this point in the history
  • Loading branch information
fstab committed Dec 27, 2018
1 parent 49d9be3 commit 6457a0b
Show file tree
Hide file tree
Showing 15 changed files with 1,167 additions and 361 deletions.
4 changes: 0 additions & 4 deletions tailer/fileTailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,6 @@ func (f *fileTailer) Errors() chan Error {
return f.errors
}

func RunFseventFileTailer(path string, readall bool, failOnMissingFile bool, logger simpleLogger) Tailer {
return runFileTailer(path, readall, failOnMissingFile, logger, NewFseventWatcher)
}

func RunPollingFileTailer(path string, readall bool, failOnMissingFile bool, pollIntervall time.Duration, logger simpleLogger) Tailer {
makeWatcher := func(abspath string, _ *File) (Watcher, error) {
return NewPollingWatcher(abspath, pollIntervall)
Expand Down
22 changes: 22 additions & 0 deletions tailer/fileTailerLegacyImplWrapper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2018 The grok_exporter Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// +build !darwin

package tailer

// 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 {
return runFileTailer(path, readall, failOnMissingFile, logger, NewFseventWatcher)
}
76 changes: 76 additions & 0 deletions tailer/fileTailerNewImplWrapper_darwin.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// Copyright 2018 The grok_exporter Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package tailer

import (
"fmt"
"github.com/fstab/grok_exporter/tailer/fswatcher"
)

type tailerWrapper struct {
lines chan string
errors chan Error
done chan struct{}
}

func (t *tailerWrapper) Close() {
close(t.done)
close(t.lines)
close(t.errors)
}

func (t *tailerWrapper) Lines() chan string {
return t.lines
}

func (t *tailerWrapper) Errors() chan Error {
return t.errors
}

// 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 {
result := &tailerWrapper{
lines: make(chan string),
errors: make(chan Error),
done: make(chan struct{}),
}

newTailer, err := fswatcher.Run([]string{path}, readall, failOnMissingFile)
if err != nil {
go func() {
result.errors <- newError("failed to initialize file system watcher", err)
}()
return result
}

go func() {
for {
select {
case l := <-newTailer.Lines():
fmt.Printf("*** forwarding line %q to wrapped tailer\n", l.Line)
result.lines <- l.Line
case e := <-newTailer.Errors():
result.errors <- newError(e.Error(), e.Cause())
result.Close()
return
case <-result.done:
newTailer.Close()
return
}
}
}()
return result
}
286 changes: 0 additions & 286 deletions tailer/fileTailer_darwin.go

This file was deleted.

Loading

0 comments on commit 6457a0b

Please sign in to comment.