The slf4j-log4j12
is a bridge (binding) from SLF4J to Log4j 1.2: all messages submitted to a org.slf4j.Logger
in your code, will be sent to a org.apache.log4j.Logger
of the same name. Its not the right direction.
Fortunately nowadays there are bridges/bindings/adapters between all major logging systems. It is not clear from your question, whether you need SLF4J at all, so:
if you don't use SLF4J, you can use log4j-1.2-api
, a direct bridge between Log4j 1.x and Log4j 2.x API. It is a replacement for Log4j 1.x, so you need to remove the log4j
artifact and add:
<!-- From Log4j 1.x to Log4j 2.x API -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-1.2-api</artifactId>
<version>2.19.0</version>
</dependency>
if you want to pass through SLF4J, you can use log4j-over-slf4j
(a replacement for Log4j 1.x that connects Log4j 1.x to SLF4J) and log4j-slf4j18-impl
(a bridge from SLF4J to the Log4j 2.x API):
<!-- From Log4j 1.x to SLF4J -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
<version>2.0.5</version>
</dependency>
<!-- From SLF4J 2.0+ to Log4j 2.x API -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j2-impl</artifactId>
<version>2.19.0</version>
<scope>runtime</scope>
</dependency>
Of course you'll also need an implementation of the Log4j 2.x API, like Log4j 2.x Core:
<!-- From Log4j 2.x API to Log4j 2.x Core -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.19.0</version>
<scope>runtime</scope>
</dependency>
slf4j-log4j12
contains log4j v1.2. Redirecting slf4j API to log4j is uncommon, therefore I recommend you to instead use slf4j + logback and the redirect the log4j requests to slf4j. – Testis