Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
log4j output in JSON format
Java
branch: master

This branch is 7 commits ahead, 2 commits behind michaeltandy:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
.gitignore
pom.xml
readme.md

readme.md

log4j-json

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.

What does the output look like?

{"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!

What should I put in my log4j properties file?

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

I want to upload to Google BigQuery, what schema should I use?

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

What license is it under?

This project is (c) Michael Tandy it's released under the MIT license.

Something went wrong with that request. Please try again.