Skip to content

Commit

Permalink
extends regex for json logs
Browse files Browse the repository at this point in the history
  • Loading branch information
M4tteoP committed Dec 9, 2024
1 parent 6c1b1cb commit 2a7779a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion waflog/read.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (ll *FTWLogLines) TriggeredRules() []uint {
ll.triggeredRulesInitialized = true

lines := ll.getMarkedLines()
regex := regexp.MustCompile(`\[id "(\d+)"\]|"id":\s*"?(\d+)"?`)
regex := regexp.MustCompile(`\[id \\?"(\d+)\\?"\]|"id":\s*"?(\d+)"?`)
for _, line := range lines {
log.Trace().Msgf("ftw/waflog: Looking for any rule in '%s'", line)
match := regex.FindAllSubmatch(line, -1)
Expand Down
7 changes: 4 additions & 3 deletions waflog/read_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,11 +371,11 @@ func (s *readTestSuite) TestFindAllIdsInLogs() {
markerLine := "X-cRs-TeSt: " + stageID
logLines := fmt.Sprint("\n", markerLine,
`[id "1"] something else [id "2"]`,
`"id": 3, something else {"id":4}`+"\n",
`"id": 3, something else {"id":4},`,
`something else [id \"5\"]`+"\n",
"\n", markerLine)
filename, err := utils.CreateTempFileWithContent(logLines, "test-errorlog-")
s.Require().NoError(err)

cfg.LogFile = filename
log, err := os.Open(filename)
s.Require().NoError(err)
Expand All @@ -388,9 +388,10 @@ func (s *readTestSuite) TestFindAllIdsInLogs() {
ll.WithEndMarker([]byte(markerLine))

foundRuleIds := ll.TriggeredRules()
s.Len(foundRuleIds, 4)
s.Len(foundRuleIds, 5)
s.Contains(foundRuleIds, uint(1))
s.Contains(foundRuleIds, uint(2))
s.Contains(foundRuleIds, uint(3))
s.Contains(foundRuleIds, uint(4))
s.Contains(foundRuleIds, uint(5))
}

0 comments on commit 2a7779a

Please sign in to comment.