Skip to content

wmudge/java-grok

 
 

Repository files navigation

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?

  • reporting errors and other patterns from logs and processes
  • parsing complex text output and converting it to json for external processing
  • apply 'write-once use-everywhere' to regular expressions
  • automatically providing patterns for unknown text inputs (logs you want patterns generated for future matching)

Maven repository

<dependency>
  <groupId>io.thekraken</groupId>
  <artifactId>grok</artifactId>
  <version>0.1.1</version>
</dependency>

Or with gradle

compile "io.thekraken:grok:0.1.1"

Example of how to use java-grok:

/** Create a new grok instance */
Grok grok = Grok.create("patterns/patterns");

/** Grok pattern to compile, here httpd logs */
grok.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);
gm.captures();

/** Get the output */
System.out.println(gm.toJson());

Build Java Grok

Java Grok support Gradle: ./gradlew build

Getting help

Maintainer: @anthonycorbacho

Thankx to

Any contributions are warmly welcome

Grok is inspired by the logstash inteceptor or filter available here

About

Simple API that allows you to easily parse logs and other files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%