Apache logging services logo Apache log4j logo

Maven, Ivy, and Gradle Artifacts

Log4j 2 is broken up in an API and an implementation (core), where the API provides the interface that applications should code to. Strictly speaking Log4j core is only needed at runtime and not at compile time.

However, below we list Log4j core as a compile time dependency to improve the startup time for custom plugins.

Using Log4j in your Apache Maven build

To build with Apache Maven, add the dependencies listed below to your pom.xml file.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.3.2</version>
  </dependency>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.3.2</version>
  </dependency>
</dependencies>

Using Log4j in your Apache Ivy build

To build with Apache Ivy, add the dependencies listed below to your ivy.xml file.

ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-api" rev="2.3.2" />
  <dependency org="org.apache.logging.log4j" name="log4j-core" rev="2.3.2" />
</dependencies>

Using Log4j in your Gradle build

To build with Gradle, add the dependencies listed below to your build.gradle file.

build.gradle
dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.3.2'
  compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.3.2'
}

Bill of Material

To keep your Log4j module versions in sync with each other, a BOM pom.xml file is provided for your convenience. To use this with Maven, add the dependency listed below to your pom.xml file. When you specify the version identifier in this section, you don't have to specify the version in your <dependencies/> section.

pom.xml
<dependencyManagement>
  <dependencies>
    <dependency>
      <groupId>org.apache.logging.log4j</groupId>
      <artifactId>log4j-bom</artifactId>
      <version>2.3.2</version>
      <scope>import</scope>
      <type>pom</type>
    </dependency>
  </dependencies>
</dependencyManagement>

Optional Components

Log4j 2.x contains several optional components that can be included in an application.

Log4j 1.x API Bridge

If existing components use Log4j 1.x and you want to have this logging routed to Log4j 2, then remove any log4j 1.x dependencies and add the following.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-1.2-api</artifactId>
    <version>2.3.2</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-1.2-api" rev="2.3.2" />
</dependencies>
build.gradle
dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-1.2-api', version: '2.3.2'
}

Apache Commons Logging Bridge

If existing components use Apache Commons Logging 1.x and you want to have this logging routed to Log4j 2, then add the following but do not remove any Commons Logging 1.x dependencies.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-jcl</artifactId>
    <version>2.3.2</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-jcl" rev="2.3.2" />
</dependencies>
build.gradle
dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-jcl', version: '2.3.2'
}

SLF4J Bridge

If existing components use SLF4J and you want to have this logging routed to Log4j 2, then add the following but do not remove any SLF4J dependencies.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>2.3.2</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-slf4j-impl" rev="2.3.2" />
</dependencies>
build.gradle
dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.3.2'
}

JUL Adapter

If existing components use Java Util Logging and you want to have this logging routed to Log4j 2, then add the following.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-jul</artifactId>
    <version>2.3.2</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-jul" rev="2.3.2" />
</dependencies>
build.gradle
dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '2.3.2'
}

Web Servlet Support

In order to properly support and handle the ClassLoader environment and container lifecycle of a web application, an additional module is required. This module is only required at runtime. In addition, if you're using servlets in an OSGi environment, make sure your preferred version of the servlet API is already available (e.g., if you want to use 3.0, but you've also got 2.5 loaded, make sure both are loaded).

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-web</artifactId>
    <version>2.3.2</version>
    <scope>runtime</scope>
  </dependency>
</dependencies>
          
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-web" rev="2.3.2" />
</dependencies>
          
build.gradle
dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-web', version: '2.3.2'
}
          

Tag Library

The Log4j Log Tag Library creates the capability of inserting log statements in JSPs without the use of Java scripting. It uses the standard Log4j 2 API to log messages according to your Log4j configuration.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-taglib</artifactId>
    <version>2.3.2</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-taglib" rev="2.3.2" />
</dependencies>
build.gradle
dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-taglib', version: '2.3.2'
}

Apache Flume Appender

The Flume Appender allows applications to send events to Flume Agents.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-flume-ng</artifactId>
    <version>2.3.2</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-flume-ng" rev="2.3.2" />
</dependencies>
build.gradle
dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-flume-ng', version: '2.3.2'
}

Log4j to SLF4J Adapter

The Log4j 2 to SLF4J Adapter allows applications coded to the Log4j 2 API to be routed to SLF4J. Use of this adapter may cause some loss of performance as the Log4j 2 Messages must be formatted before they can be passed to SLF4J. The SLF4J Bridge must NOT be on the class path when this is in use.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-to-slf4j</artifactId>
    <version>2.3.2</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-to-slf4j" rev="2.3.2" />
</dependencies>
build.gradle
dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-to-slf4j', version: '2.3.2'
}

NoSQL Appenders

If your configuration uses one of the NoSQL Appenders, then add the following.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-nosql</artifactId>
    <version>2.3.2</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-nosql" rev="2.3.2" />
</dependencies>
build.gradle
dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-nosql', version: '2.3.2'
}

IO Streams

Log4j IO Streams allow applications to have data that is written to an OutputStream or a Writer be redirected to a Logger, or have data that is read from an InputStream or a Reader be wiretapped by a Logger. To use IO Streams, add the following.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-iostreams</artifactId>
    <version>2.3.2</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-iostreams" rev="2.3.2" />
</dependencies>
build.gradle
dependencies {
  compile group: 'org.apache.logging.log4j', name: 'log4j-iostreams', version: '2.3.2'
}