We are now a github organisation. You are invited to participate.
read any java log format and process it
... because i did need it:)
This will need Java 7 runtime, because of the used file io enhancement and java regex named group support.
Stable (Maven Central Repository, Released: 09.04.2013 - wait 24hrs for maven central)
<dependency>
<groupId>de.flapdoodle</groupId>
<artifactId>de.flapdoodle.logparser</artifactId>
<version>1.1</version>
</dependency>
Snapshots (Repository http://oss.sonatype.org/content/repositories/snapshots)
<dependency>
<groupId>de.flapdoodle</groupId>
<artifactId>de.flapdoodle.logparser</artifactId>
<version>1.2-SNAPSHOT</version>
</dependency>
- documentation enhancement
- major refactoring
- multi line message stacktrace support
- can handle standard java logging and some custom logback format
- supports stack trace parsing
With this library it should be easy to setup a parser for most common and custom log files The following examples will show how you can do this.
This is how you can parse a simple logfile (with stacktrace support). In this example the logfile can look like this:
2013-04-07 00:00:01 INFO: Everything is fine
2013-04-07 00:00:01 ERROR: Something went wrong
de.flapdoodle.BadCaseException: wo should stop right now
at de.flapdoodle.HarmlessComponent.simpleMethod(HarmlessComponent.java:123)
at de.flapdoodle.Main.main(Main.java:12)
Caused by: java.lang.NullPointerException: null
at de.flapdoodle.stuff.ReachTheStarAdapter.reach(ReachTheStarAdapter.java:123456)
at de.flapdoodle.stuff.ReachSomething.reach(ReachSomething.java:123456)
... 64 common frames omitted
...
String regex = "(?<date>\\d+-\\d\\d-\\d\\d \\d\\d:\\d\\d:\\d\\d) (?<level>[A-Z]+): (?<message>.*)$";
Pattern firstLinePattern = Pattern.compile(regex);
GenericLogMatcher genericLogMatcher = new GenericLogMatcher(firstLinePattern);
List<IMatcher<LogEntry>> matchers = Lists.<IMatcher<LogEntry>> newArrayList(genericLogMatcher);
IStreamListener<LogEntry> streamListener = collectingStreamListener;
ILineProcessor lineProcessor = writeToListLineProcessor;
StreamProcessor<LogEntry> streamProcessor = new StreamProcessor<LogEntry>(matchers, lineProcessor, streamListener);
...
...
int readAheadLimit = 1024;
IRewindableReader reader = new BufferedReaderAdapter(inputStream, Charsets.UTF_8, readAheadLimit);
streamProcessor.process(reader);
...