Maven, Ivy, Gradle, and SBT ArtifactsLog4j 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 as it provides an annotation processor that generates a metadata file to cache plugin information as well as the necessary code to compile against to create custom plugins. Using Log4j in your Apache Maven buildTo 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.12.4</version> </dependency> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.12.4</version> </dependency> </dependencies> Using Log4j in your Apache Ivy buildTo 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.12.4" /> <dependency org="org.apache.logging.log4j" name="log4j-core" rev="2.12.4" /> </dependencies> Using Log4j in your Gradle buildTo 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.12.4' compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.12.4' } Using Log4j in your SBT buildTo build with SBT, add the dependencies listed below to your build.sbt file. build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-api" % "2.12.4" libraryDependencies += "org.apache.logging.log4j" % "log4j-core" % "2.12.4" Bill of MaterialTo 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.12.4</version> <scope>import</scope> <type>pom</type> </dependency> </dependencies> </dependencyManagement> To use this with Gradle, an additional Gradle plugin is required for dependency management functionality. build.gradle plugins { id 'io.spring.dependency-management' version '1.0.1.RELEASE' } dependencyManagement { imports { mavenBom 'org.apache.logging.log4j:log4j-bom:2.12.4' } } dependencies { compile 'org.apache.logging.log4j:log4j-api' compile 'org.apache.logging.log4j:log4j-core' // etc. } Optional ComponentsLog4j 2.x contains several optional components that can be included in an application. Log4j 1.x API BridgeIf 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.12.4</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-1.2-api" rev="2.12.4" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-1.2-api', version: '2.12.4' } build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-1.2-api" % "2.12.4" Apache Commons Logging BridgeIf 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.12.4</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-jcl" rev="2.12.4" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-jcl', version: '2.12.4' } build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-jcl" % "2.12.4" SLF4J BridgeIf 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.12.4</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-slf4j-impl" rev="2.12.4" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-slf4j-impl', version: '2.12.4' } build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-slf4j-impl" % "2.12.4" JUL AdapterIf 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.12.4</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-jul" rev="2.12.4" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-jul', version: '2.12.4' } build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-jul" % "2.12.4" Web Servlet SupportIn 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.12.4</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-web" rev="2.12.4" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-web', version: '2.12.4' } build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-web" % "2.12.4" Tag LibraryThe 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.12.4</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-taglib" rev="2.12.4" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-taglib', version: '2.12.4' } build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-taglib" % "2.12.4" Apache Flume AppenderThe 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.12.4</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-flume-ng" rev="2.12.4" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-flume-ng', version: '2.12.4' } build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-flume-ng" % "2.12.4" Log4j to SLF4J AdapterThe 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.12.4</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-to-slf4j" rev="2.12.4" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-to-slf4j', version: '2.12.4' } build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-to-slf4j" % "2.12.4" CouchDBIf your configuration uses the NoSQL CouchDB appender, then add the following. pom.xml <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-couchdb</artifactId> <version>2.12.4</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-couchdb" rev="2.12.4" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-couchdb', version: '2.12.4' } build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-couchdb" % "2.12.4" MongoDBIf your configuration uses the NoSQL MongoDB appender, then add the following. pom.xml <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-mongodb</artifactId> <version>2.12.4</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-mongodb" rev="2.12.4" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-mongodb', version: '2.12.4' } build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-mongodb" % "2.12.4" CassandraIf your configuration uses the Cassandra appender, then add the following. pom.xml <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-cassandra</artifactId> <version>2.12.4</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-cassandra" rev="2.12.4" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-cassandra', version: '2.12.4' } build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-cassandra" % "2.12.4" IO StreamsLog4j 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.12.4</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-iostreams" rev="2.12.4" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-iostreams', version: '2.12.4' } build.sbt libraryDependencies += "org.apache.logging.log4j" % "log4j-iostreams" % "2.12.4" Scala APIA convenient Scala wrapper for the Logger API. SBT users can add the following to their build.sbt: build.sbt libraryDependencies += "org.apache.logging.log4j" %% "log4j-api-scala" % "11.0" Maven, Ivy, and Gradle users need to add the Scala version to the artifact name. Scala 2.12 users can use the following: pom.xml <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api-scala_2.12</artifactId> <version>11.0</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-api-scala_2.12" rev="11.0" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-api-scala_2.12', version: '11.0' } Scala 2.11 users can use the following: pom.xml <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api-scala_2.11</artifactId> <version>11.0</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-api-scala_2.11" rev="11.0" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-api-scala_2.11', version: '11.0' } Scala 2.10 users can use the following: pom.xml <dependencies> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api-scala_2.10</artifactId> <version>11.0</version> </dependency> </dependencies> ivy.xml <dependencies> <dependency org="org.apache.logging.log4j" name="log4j-api-scala_2.10" rev="11.0" /> </dependencies> build.gradle dependencies { compile group: 'org.apache.logging.log4j', name: 'log4j-api-scala_2.10', version: '11.0' } Snapshot buildsYou can access the latest development snapshot by using the Maven repository https://repository.apache.org/snapshots and the current SNAPSHOT version. Generally, the master branch will use the next patch version as its snapshot version regardless of what the next actual version of Log4j will be. For example, if the latest release were 2.0, then master would be using the version 2.0.1-SNAPSHOT. Always verify with pom.xml in the master branch as described in the source repository page. MavenMaven users can add the following to their pom.xml to enable snapshots: <repositories> <repository> <id>apache.snapshots</id> <name>Apache Snapshot Repository</name> <url>https://repository.apache.org/snapshots</url> <releases> <enabled>false</enabled> </releases> </repository> </repositories> |