Skip to content

Switch to SLF4J 2.x for implicit Log4J implementation dependency. #1180

Closed
@garretwilson

Description

@garretwilson

It would appear from the dependencies that you're using the older series of SLF4J 1.x, because you're using the Log4j SLF4J 1.x implementation:

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j-impl</artifactId>
        </dependency>

The big problem with SLF4J 1.x is that is it uses a static class that is included cross-package in the implementation JAR, breaking Java modularization and other things. Everyone should be switching to SLF4J 2.x as soon as possible.

The good news is that SLF4J 2.x is backwards-compatible, so that when you simply switch your library to SLF4J 2.x, all your code works the same. (You can use new features if you want.) But by including the SLF4J 1.x implementation of Log4J, you are forcing an application to use the old version which prevents the use of modern Java features and prevents an application from moving forward to SLF4J 2.x

Instead you should be using:

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-slf4j2-impl</artifactId>
        </dependency>

See Log4j 2 SLF4J Binding and What has changed in SLF4J version 2.0.0?.

A developer may be able to work around this by adding a Maven exclude for org.apache.logging.log4j:log4j-slf4j-impl and manually adding a dependency to org.apache.logging.log4j:log4j-slf4j2-impl. (I haven't tried this.)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions