Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable TestFollow #109

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:

- name: Test
# TestFollow fails to work in GitHub Actions. Likely a result of permissions. Will investigate further later
run: go test -race -covermode=atomic -coverprofile=coverage.txt -v -skip TestFollow ./...
run: go test -race -covermode=atomic -coverprofile=coverage.txt -v ./...

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v3
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func main() {
logFiles := viper.GetStringSlice("logs")
for _, logFile := range logFiles {
//begin watching the file in a goroutine for concurrency
go Follow(logFile, pubSub, patterns)
go Follow(logFile, pubSub, patterns, false)
}

// startup the web server
Expand Down
12 changes: 10 additions & 2 deletions tailer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ import (
"github.com/cskr/pubsub"
"github.com/jdrews/go-tailer/fswatcher"
"github.com/jdrews/go-tailer/glob"
"time"
)

// Follow begins a tailer for the specified logFilePath and publishes log lines to the given pubSub message broker
// When Follow picks up a log line, it also runs the line through regex via func Colorize
// to determine if it matches a color pattern
func Follow(logFilePath string, pubSub *pubsub.PubSub, patterns []CompiledRegexColors) {
func Follow(logFilePath string, pubSub *pubsub.PubSub, patterns []CompiledRegexColors, polling bool) {

var tailer fswatcher.FileTailer

parsedGlob, err := glob.Parse(logFilePath)
if err != nil {
panic(fmt.Sprintf("%q: failed to parse glob: %q", parsedGlob, err))
}

tailer, err := fswatcher.RunFileTailer([]glob.Glob{parsedGlob}, false, true, logger)
if polling {
tailer, err = fswatcher.RunPollingFileTailer([]glob.Glob{parsedGlob}, false, true, 10*time.Millisecond, logger)
} else {
tailer, err = fswatcher.RunFileTailer([]glob.Glob{parsedGlob}, false, true, logger)
}

for line := range tailer.Lines() {
logger.Debug(line.Line)
logMessage := Colorize(line.Line, line.File, patterns)
Expand Down
2 changes: 1 addition & 1 deletion tailer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func TestFollow(t *testing.T) {
defer pubSub.Unsub(linesChannel, "lines")

// Run Follow
go Follow(logFilePath, pubSub, compiledRegexColors)
go Follow(logFilePath, pubSub, compiledRegexColors, true)

// Give the fswatcher.RunFileTailer enough time to startup
time.Sleep(time.Duration(2000) * time.Millisecond)
Expand Down