Skip to content

Commit

Permalink
Pass excludePatterns to all parsers
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidVentura committed Apr 1, 2024
1 parent cf8c8e3 commit 4d46203
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
9 changes: 7 additions & 2 deletions logscan/logscan.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,15 @@ func makeNew(format, date, tyme, datetime string, exclude []string) (*Scanner, e
var p LineParser
var err error

excludePatt, err := processExcludes(exclude)
if err != nil {
return nil, err
}

if format == "caddy" {
p = CaddyParser{datetime: datetime}
p = CaddyParser{datetime: datetime, excludePatterns: excludePatt}
} else {
p, err = newRegexParser(format, date, tyme, datetime, exclude)
p, err = newRegexParser(format, date, tyme, datetime, excludePatt)
}
if err != nil {
return nil, err
Expand Down
10 changes: 3 additions & 7 deletions logscan/regex_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,14 @@ func (p RegexParser) Parse(line string) (Line, bool, error) {

var _ LineParser = RegexParser{}

func newRegexParser(format, date, tyme, datetime string, exclude []string) (*RegexParser, error) {
func newRegexParser(format, date, tyme, datetime string, exclude []excludePattern) (*RegexParser, error) {
of := format
format, date, tyme, datetime = getFormat(format, date, tyme, datetime)
if format == "" {
return nil, errors.Errorf("unknown format: %s", of)
}

excludePatt, err := processExcludes(exclude)
if err != nil {
return nil, err
}

var err error
pat := reFormat.ReplaceAllStringFunc(regexp.QuoteMeta(format), func(m string) string {
m = m[2:]

Expand Down Expand Up @@ -129,7 +125,7 @@ func newRegexParser(format, date, tyme, datetime string, exclude []string) (*Reg
date: date,
time: tyme,
datetime: datetime,
exclude: excludePatt,
exclude: exclude,
}, nil
}

Expand Down

0 comments on commit 4d46203

Please sign in to comment.