https://github.com/thekrakken/java-grok
I'm using this Grok API for Java. Code is as follows:
Grok grok = Grok.EMPTY;
// add a pattern to grok
grok.addPatternFromFile("pat.txt");
// compile and add semantic
grok.compile("%{NUMBER:hits} %{USER:word}");
String str = "234 wdfd\n";
Match m = grok.match(str);
m.captures();
// Print
System.out.println(m.toJson());
grok = Grok.EMPTY;
str = "ssdfsdf\n";
Match m2 = grok.match(str);
m2.captures();
System.out.println(m2.toJson());
The output of the program is:
{"hits":234,"word":"wdfd"}
{"hits":234,"word":"wdfd"}
I emptied the Grok instance, I used a separate "m2" match variable, but still the program returns the last successful match instead of NULL or an error that can inform me that the match has failed. How can I know when a match fails?