log4j2slf4j

Log4j update from 2.23.1 to 2.24.0/1 -> logging gone


I have a big and old legacy project where we updated to log4j 2 very painfully and we use a lot of bridges.

            <!-- LOGGING -->
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-1.2-api</artifactId>
                <version>${log4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-slf4j2-impl</artifactId>
                <version>${log4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.apache.logging.log4j</groupId>
                <artifactId>log4j-web</artifactId>
                <version>${log4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>slf4j-api</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>jul-to-slf4j</artifactId>
                <version>${slf4j.version}</version>
            </dependency>
            <dependency>
                <groupId>org.slf4j</groupId>
                <artifactId>jcl-over-slf4j</artifactId>
                <version>${slf4j.version}</version>
            </dependency>

slf4j version is 2.0.16

In the release notes of log4j 2.24.0 is this text:

Bridges The JUL-to-Log4j API and Log4j 1-to-Log4j API will no longer be able to modify the configuration of Log4j Core by default. If such a functionality is required, it must be explicitly enabled.

After the update from 2.23.1 to 2.24.0 or 2.24.1 the logging was gone.

I did not found any hint in the documentation how to enable this bridge functionality.


Solution

  • Note: The "bridging" capability of the log4j-1.2-api and log4j-jul was not disabled in 2.24.0. The bridges still work out of the box to forward log statement written using Log4j 1 or java.util.logging to Log4j 2 API. What has been disabled is the ability to load and modify the configuration of the logging implementation using these legacy APIs. The rationale behind this is that many legacy libraries break user configurations by calling methods like j.u.l.Logger.setLevel() or org.apache.log4j.PropertyConfigurator.configure(). Since it is not possible to modify these legacy libraries, the "configuration" part of the bridges became an opt-in.

    Possible cause of your problem

    Many applications and libraries, including probably yours, contain a snippet similar to this one:

    org.apache.log4j.PropertyConfigurator.configure(
            Main.class.getClassLoader().getResourceAsStream("log4j.properties"));
    

    Such a snippet has never been required since the first stable release of Log4j 1.0 already loaded the log4j.properties file automatically and allowed user to specify an alternate location with the log4j.configuration system property. Such snippets should be removed and replaced with one of these options:

    If you really want to keep the snippet (which I don't recommend), you should set the log4j1.compatibility system property to true.