Log4j Over Slf4j Maven

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 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.

MavenLog4j Over Slf4j Maven

In this tutorial, we're going to examine Lombok log annotations like @Slf4j, @Log4j or @Log. Use Log Annotations. Lombok provides several log annotations to work with different logging libraries. Log4j Implemented Over SLF4J - Log4j implemented over SLF4J. Maven Central Repository Search Quick Stats Report A Vulnerability GitHub Search. Close search org.slf4j:log4j-over-slf4j. Log4j Implemented Over SLF4J.

Using Log4j in your Apache Maven build

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

pom.xml

Using Log4j in your Apache Ivy build

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

ivy.xml

Using Log4j in your Gradle build

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

build.gradle

Using Log4j in your SBT build

To build with SBT, add the dependencies listed below to your build.sbt file.

build.sbt

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

To use this with Gradle, an additional Gradle plugin is required for dependency management functionality.

build.gradle

Optional Components

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

Log4j

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

ivy.xml

build.gradle

build.sbt

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

ivy.xml

build.gradle

build.sbt

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

Exclude Log4j-over-slf4j Maven

ivy.xml

build.gradle

build.sbt

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

ivy.xml

build.gradle

build.sbt

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

ivy.xml

build.gradle

build.sbt

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

Over

ivy.xml

build.gradle

build.sbt

Apache Flume Appender

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

pom.xml

ivy.xml

build.gradle

build.sbt

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.

Log4j Over Slf4j Maven

pom.xml

ivy.xml

build.gradle

build.sbt

CouchDB

If your configuration uses the NoSQL CouchDB appender, then add the following.

Log4j To Slf4j

pom.xml

ivy.xml

build.gradle

build.sbt

MongoDB

If your configuration uses the NoSQL MongoDB appender, then add the following.

pom.xml

ivy.xml

build.gradle

build.sbt

Cassandra

If your configuration uses the Cassandra appender, then add the following.

pom.xml

ivy.xml

build.gradle

build.sbt

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

ivy.xml

build.gradle

build.sbt Powerpod lanc.

Scala API

A convenient Scala wrapper for the Logger API. SBT users can add the following to their build.sbt:

build.sbt

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

ivy.xml

build.gradle

Scala 2.11 users can use the following:

pom.xml

ivy.xml

build.gradle

Scala 2.10 users can use the following:

pom.xml

ivy.xml

build.gradle

Snapshot builds

You 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.

Maven

Log4j-over-slf4j-1.6.1.jar Maven Dependency

Maven users can add the following to their pom.xml to enable snapshots:

Gradle

Gradle users can add the following to their build.gradle to enable snapshots:

SBT

Slf4j Logback Maven

SBT users can add the following to their build.sbt to enable snapshots: