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

Grok

Build Status

Java Grok is simple API that allows you to easily parse logs and other files (single line). With Java Grok, you can turn unstructured log and event data into structured data (JSON).


What can I use Grok for?

Maven repository

<dependency>
  <groupId>io.krakens</groupId>
  <artifactId>java-grok</artifactId>
  <version>0.1.9</version>
</dependency>

Or with gradle

compile "io.krakens:java-grok:0.1.9"

Old release (Link)

Usage (Grok java documentation)

Example of how to use java-grok:

/* Create a new grokCompiler instance */
GrokCompiler grokCompiler = GrokCompiler.newInstance();
grokCompiler.registerDefaultPatterns();

/* Grok pattern to compile, here httpd logs */
final Grok grok = grokCompiler.compile("%{COMBINEDAPACHELOG}");

/* Line of log to match */
String log = "112.169.19.192 - - [06/Mar/2013:01:36:30 +0900] \"GET / HTTP/1.1\" 200 44346 \"-\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22\"";

Match gm = grok.match(log);

/* Get the map with matches */
final Map<String, Object> capture = gm.capture();

Build Java Grok

Java Grok support Gradle: ./gradlew assemble

Getting help

Mailling List

Thanks to

Any contributions are warmly welcome

Grok is inspired by the logstash inteceptor or filter available here