Skip to content

Commit

Permalink
Force tail from end of file, no old lines
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremy5189 committed Aug 14, 2024
1 parent c50244c commit fc18981
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions internal/regex_rate_limiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package internal
import (
"bytes"
"encoding/json"
"io"
"log"
"strconv"
"strings"
Expand All @@ -33,7 +34,13 @@ func RunLogTailer(
// if TailFile() fails or we hit EOF, we should retry
for {
defer wg.Done()
t, err := tail.TailFile(config.ServerLogFile, tail.Config{Follow: true})
t, err := tail.TailFile(config.ServerLogFile, tail.Config{
Follow: true,
Location: &tail.SeekInfo{
Offset: 0,
Whence: io.SeekEnd,
},
})
if err != nil {
log.Println("RunLogTailer: log tailer failed to start. waiting a bit and trying again.")
} else {
Expand Down Expand Up @@ -200,7 +207,24 @@ func consumeLine(
}

rateLimitMutex.Lock()
// log.Println(line.Text[secondSpace+firstSpace+2:])
// Apply per site regex first
if perSiteRegex, exists := config.PerSiteRegexWithRates[urlString]; exists {
for _, regex_with_rate := range perSiteRegex {
applyRegexToLog(
banner,
config,
regex_with_rate,
ipToRegexStates,
timeIpRest,
timestamp,
ipString,
urlString,
&consumeLineResult,
false,
)
}
}
// Apply global regexes later
for _, regex_with_rate := range config.RegexesWithRates {
applyRegexToLog(
banner,
Expand Down Expand Up @@ -234,7 +258,7 @@ func applyRegexToLog(
) {
// log apply regex_with_rate.Rule
if config.Debug {
log.Println("Apply regex (global ", globalRegex, "): ", regex_with_rate.Rule)
log.Printf("Apply regex (global %v): %s", globalRegex, regex_with_rate.Rule)
}

ruleResult := RuleResult{}
Expand Down

0 comments on commit fc18981

Please sign in to comment.