Skip to content

Commit

Permalink
rework fswatcher channel read to be more efficient
Browse files Browse the repository at this point in the history
  • Loading branch information
jdrews committed Mar 27, 2023
1 parent bd65237 commit 6b5a2cf
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,20 +190,15 @@ func follow(logFilePath string, pubSub *pubsub.PubSub, patterns []CompiledRegexC
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)
for {
select {
case line := <-tailer.Lines():
logger.Debug(line.Line)
logMessage := colorize(line.Line, logFilePath, patterns)
pubSub.Pub(logMessage, "lines")
default:
continue
}
for line := range tailer.Lines() {
logger.Debug(line.Line)
logMessage := colorize(line.Line, logFilePath, patterns)
pubSub.Pub(logMessage, "lines")
}

}

// Run each line through the regex patterns to determine if the line should be colored.
Expand Down

0 comments on commit 6b5a2cf

Please sign in to comment.