From 4d4620387976e7b90392a0e484dc4ae415365d2d Mon Sep 17 00:00:00 2001 From: David Ventura Date: Mon, 1 Apr 2024 12:30:24 +0200 Subject: [PATCH] Pass excludePatterns to all parsers --- logscan/logscan.go | 9 +++++++-- logscan/regex_parser.go | 10 +++------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/logscan/logscan.go b/logscan/logscan.go index 1ea1f387..9b390b1f 100644 --- a/logscan/logscan.go +++ b/logscan/logscan.go @@ -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 diff --git a/logscan/regex_parser.go b/logscan/regex_parser.go index 85386454..f25ea473 100644 --- a/logscan/regex_parser.go +++ b/logscan/regex_parser.go @@ -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:] @@ -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 }