Apache logging services logo Apache log4j logo

Maven and Ivy Artifacts

Using Log4j in your Apache Maven build

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

<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-api</artifactId>
    <version>2.0-beta7</version>
  </dependency>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-core</artifactId>
    <version>2.0-beta7</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.

<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-api" rev="2.0-beta7" />
  <dependency org="org.apache.logging.log4j" name="log4j-core" rev="2.0-beta7" />
</dependencies>

Optional Components

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

Log4j 1.x API Bridge

If there are existing components that are written to use Log4j 1.x and it is desired 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.0-beta7</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-1.2-api" rev="2.0-beta7" />
</dependencies>

Apache Commons Logging Bridge

Commons Logging is used in many components as a way of letting applications choose the specific logging implementation. To route logging from those components into Log4j 2 include the following dependency and do not remove the Commons Logging jar.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-jcl</artifactId>
    <version>2.0-beta7</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-jcl" rev="2.0-beta7" />
</dependencies>

SLF4J Bridge

SLF4J is another popular logging API that may be bound to Log4j 2 by including the following dependency along with the SLF4J dependencies.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-slf4j-impl</artifactId>
    <version>2.0-beta7</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-slf4j-impl" rev="2.0-beta7" />
</dependencies>

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.0-beta7</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-taglib" rev="2.0-beta7" />
</dependencies>

Log4j Web

The Log4j Web artifact contains classes that can be used to initialize logging within a web application.

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-web</artifactId>
    <version>2.0-beta7</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-web" rev="2.0-beta7" />
</dependencies>

Apache Flume NG Appender

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

pom.xml
<dependencies>
  <dependency>
    <groupId>org.apache.logging.log4j</groupId>
    <artifactId>log4j-flume-ng</artifactId>
    <version>2.0-beta7</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-flume-ng" rev="2.0-beta7" />
</dependencies>

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.0-beta7</version>
  </dependency>
</dependencies>
ivy.xml
<dependencies>
  <dependency org="org.apache.logging.log4j" name="log4j-to-slf4j" rev="2.0-beta7" />
</dependencies>