log4j Getting started with log4j

30% OFF - 9th Anniversary discount on Entity Framework Extensions until December 15 with code: ZZZANNIVERSARY9


This section provides an overview of what log4j is, and why a developer might want to use it.

It should also mention any large subjects within log4j, and link out to the related topics. Since the Documentation for log4j is new, you may need to create initial versions of those related topics.

Log4j Lifecycle

Log4j 1.x is end-of-life as of August 5, 2015. [1][2]. Apache Log4j 2 is the successor to Log4j 1.x.

1 https://logging.apache.org/log4j/1.2/
[2] https://blogs.apache.org/foundation/entry/apache_logging_services_project_announces


VersionNoticeRelease Date
2.8latest version2017-01-21
2.4Log4j 2.4 and greater requires Java 72015-09-20
2.3.6last version that support java 62015-05-15
2.0first stable version of branch 2.x. Breaks api compatibility. Use bridge: log4j-1.2-api.jar2014-07-01
1.2.17EOF log4j branch 1.x2015-08-05

Installation and Setup


Installation of Log4j2 is as simple as putting log4j2 jar in application classpath. Though you might want to customize logs output through additional config file



To add log4j to project in maven, add it's dependency: In pom.xml add following dependency:


springboot with maven

Spring-boot is commonly used framework for web application. It features support auto-configuration for many features including logging façade like log4j2. To add log4j2 to your spring-boot project make sure you exclude default logging façade: commons-logging. Log4j will be used, when it is only logging façade on classpath.

        <!-- exclude spring-boot java commons logging in favour of log4j2 -->
    <!-- add log4j2 to spring-boot: -->

Notice, that there is no version in above snippet. It is because project inherit version from parent. Make sure you also inherit from spring-boot-starter-parent, by adding:



In ivy.xml, add following dependency:

  <dependency org="org.apache.logging.log4j" name="log4j-api" rev="${log4j2.version}" />
  <dependency org="org.apache.logging.log4j" name="log4j-core" rev="${log4j2.version}" />


In your .gradle file:

dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.6.2'
  compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.6.2'

Got any log4j Question?