use of io.thekraken.grok.api.exception.GrokException in project LogHub by fbacchella.
the class Grok method configure.
@Override
public boolean configure(Properties properties) {
Helpers.ThrowingConsumer<InputStream> grokloader = is -> grok.addPatternFromReader(new InputStreamReader(new BufferedInputStream(is)));
try {
Helpers.readRessources(properties.classloader, PATTERNSFOLDER, grokloader);
customPatterns.forEach((k, v) -> {
try {
grok.addPattern(k.toString(), v.toString());
} catch (GrokException e) {
logger.warn("invalid grok pattern {}: {}", k, v);
}
});
// Switch to true when https://github.com/thekrakken/java-grok/issues/61 is fixed
grok.compile(pattern, false);
} catch (IOException | URISyntaxException e) {
logger.error("unable to load patterns: {}", e.getMessage());
logger.catching(Level.DEBUG, e);
return false;
} catch (GrokException | PatternSyntaxException e) {
logger.error("wrong pattern {}: {}", pattern, e.getMessage());
logger.catching(Level.DEBUG, e);
return false;
}
return super.configure(properties);
}
use of io.thekraken.grok.api.exception.GrokException in project incubator-gobblin by apache.
the class GrokToJsonConverter method init.
@Override
public Converter<String, JsonArray, String, JsonObject> init(WorkUnitState workUnit) {
super.init(workUnit);
String pattern = workUnit.getProp(GROK_PATTERN);
String patternsFile = workUnit.getProp(BASE_PATTERNS_FILE);
this.nullStringRegexes = DatasetFilterUtils.getPatternsFromStrings(workUnit.getPropAsList(NULLSTRING_REGEXES, ""));
InputStreamReader grokPatterns;
try {
if (patternsFile == null) {
grokPatterns = new InputStreamReader(getClass().getResourceAsStream("/grok/grok-base-patterns"), "UTF8");
} else {
grokPatterns = new InputStreamReader(new FileInputStream(patternsFile), "UTF8");
}
grok = new Grok();
grok.addPatternFromReader(grokPatterns);
grok.compile(pattern);
} catch (GrokException | FileNotFoundException | UnsupportedEncodingException e) {
throw new RuntimeException("Error initializing GROK: " + e);
}
return this;
}
Aggregations