thekrakken / java-grok

Simple API that allows you to easily parse logs and other files
http://grok.nflabs.com/
Other
360 stars 151 forks source link

Custom date format doesn't work with hyphens #33

Closed joschi closed 6 years ago

joschi commented 9 years ago

Custom date formats (e. g. %{PATTERN:my_date;datetime;dd/MM/yyyy}) don't seem to work if hyphens ('-') are being used in the date pattern.

If the date pattern contains a hyphen, Grok fails with the following exception:

java.util.regex.PatternSyntaxException: Illegal repetition near index 4
Foo %{DATA:result;date;yyyy-MM-dd} Bar
    ^
    at java.util.regex.Pattern.error(Pattern.java:1955)
    at java.util.regex.Pattern.closure(Pattern.java:3157)
    at java.util.regex.Pattern.sequence(Pattern.java:2134)
    at java.util.regex.Pattern.expr(Pattern.java:1996)
    at java.util.regex.Pattern.compile(Pattern.java:1696)
    at java.util.regex.Pattern.<init>(Pattern.java:1351)
    at java.util.regex.Pattern.compile(Pattern.java:1054)
    at com.google.code.regexp.Pattern.buildStandardPattern(Unknown Source)
    at com.google.code.regexp.Pattern.<init>(Unknown Source)
    at com.google.code.regexp.Pattern.compile(Unknown Source)
    at oi.thekraken.grok.api.Grok.compile(Grok.java:376)
    at io.thekraken.grok.api.GrokTest.test020_datetime_pattern_with_with_hyphens(GrokTest.java:572)

I've added some tests in joschi/java-grok@a84a1c0efce25885bfc8cb68d30954540bd7a2b8 to illustrate the issue (18 and 19 are working, 20 will fail with the exception above).