A JSON layout for Log4J (v1.2). This project is based on the GitHub project thmshmm/log4j-json-layout but uses more recent version of Java, Maven and dependent libraries.
{"timestamp":"<DATE>","level":"<LEVEL>","logger":"<LOGGER>","thread":"<THREAD>","message":"<MESSAGE>","stacktrace":"<STACKTRACE>"}
The "stacktrace" item is optional and will only be in the JSON object if the log message has a trace message.
log4j.appender.myAppender=org.apache.log4j.DailyRollingFileAppender
log4j.appender.myAppender.File=/var/log/my.log
log4j.appender.myAppender.layout=com.github.wildbeavers.log4j12jsonlayout.JsonLayout
log4j.appender.myAppender.layout.DatePattern=yyyy-MM-dd HH:mm:ss,SSS
Name | Options | Default |
---|---|---|
DatePattern | all valid SimpleDateFormat patterns | yyyy-MM-dd HH:mm:ss,SSS |
- JSON parser: FasterXML/jackson-core
This project has been created for supporting JSON logging for Kafka and ZooKeeper. Both projects already contain the required libraries. - JAVA Version: 8
- a long supported Java version has to be selected => LTS version required
- a recent but not bleeding edge version is required
- a version which can be used by legacy enterprise applications is required
-
The pom.xml contains at the beginning a list of properties with the versions of the dependent libraries. Update these values to match with the Kafka / ZooKeeper version (always choose the smaller version when they are different)
-
Local build:
mvn package
-
Release build
-
Update version at pom.xml
-
Build JAR inside a Docker container
docker build . -t log4j12-json-layout:latest
-
Copy the JAR to the local filesystem:
docker run -v ${PWD}:/local log4j12-json-layout:latest bash -c "cp /target/log4j12-json-layout-*.jar /local/ && chmod ugo+w /local/*"
-
Create new release at Github and attach JAR
-
There are several projects with a similar scope:
- log4j-json
- last release Nov 28, 2012 / commit Mar 27, 2015
- depends on google/gson
- log4j-json-layout
- last release
none
/ commit Dec 1, 2017 - depends on FasterXML/jackson-core
- last release
- log4j-jsonevent-layout
- last release Sep 9, 2014 / last commit Sep 9, 2014
- depends on json-smart