-
Notifications
You must be signed in to change notification settings - Fork 154
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5 prepare macOS file tailer for multiple log file support
- Loading branch information
Showing
15 changed files
with
1,167 additions
and
361 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.