diff --git a/app/startup.go b/app/startup.go index 3a3436f..54d9097 100644 --- a/app/startup.go +++ b/app/startup.go @@ -3,6 +3,7 @@ package app import ( "encoding/json" "fmt" + "log" "os" "regexp" "strings" @@ -26,7 +27,7 @@ func (c *Conf) setup() { compiled, err := regexp.Compile(fmt.Sprintf("^%v$", pattern.Regex)) if err != nil { - logger.Fatalf("Bad configuration: pattern %v doesn't compile!", patternName) + logger.Fatalf("Bad configuration: pattern %v: %v", patternName, err) } c.Patterns[patternName].Regex = fmt.Sprintf("(?P<%s>%s)", patternName, pattern.Regex) for _, ignore := range pattern.Ignore { @@ -97,8 +98,11 @@ func (c *Conf) setup() { regex = strings.Replace(regex, pattern.nameWithBraces, pattern.Regex, 1) } } - // TODO regexp.Compile and show proper message if it doesn't instead of panicing - filter.compiledRegex = append(filter.compiledRegex, *regexp.MustCompile(regex)) + compiledRegex, err := regexp.Compile(regex) + if err != nil { + log.Fatalf("%vBad configuration: regex of filter %s.%s: %v", logger.FATAL, stream.name, filter.name, err) + } + filter.compiledRegex = append(filter.compiledRegex, *compiledRegex) } if len(filter.Actions) == 0 { diff --git a/logger/log.go b/logger/log.go index 221d45b..fdc6d8e 100644 --- a/logger/log.go +++ b/logger/log.go @@ -76,6 +76,5 @@ func Fatalln(args ...any) { } func Fatalf(format string, args ...any) { - level := FATAL - log.Fatalf(level.String()+format, args) + log.Fatalf(FATAL.String()+format, args) }