A log4j Layout to produce JSON logs. These are formatted with one logging event per line.
This is useful if you want to use your log files with something that runs on JSON such as Google BigQuery.
{"timestamp":1352412458890,"date":"Nov 8, 2012 10:07:38 PM","hostname":"michael1","username":"michael","level":"INFO","thread":"main","classname":"uk.me.mjt.log4jjson.SimpleJsonLayoutTest","filename":"SimpleJsonLayoutTest.java","linenumber":25,"methodname":"testDemonstration","message":"Example of some logging"}
You can customise the format if you like, by extending SimpleJsonLayout and overriding the method after() - or you can fork the project and change it however you like!
To log to the console:
log4j.rootLogger=INFO, a
log4j.appender.a=org.apache.log4j.ConsoleAppender
log4j.appender.a.layout=uk.me.mjt.log4jjson.SimpleJsonLayout
Here's the one I used:
timestamp:integer, date:string, hostname:string, username:string, level:string, thread:string, ndc:string, classname:string, filename:string, linenumber:integer, methodname:string, message:string, throwable:string
This project is (c) Michael Tandy it's released under the MIT license.