Search code examples
log4jslf4jlog4j2bridge

slf4j-log4j bridge with log4j 2.8.1


I am working on removing any dependencies on log4j 1.x versions as they have EOL'd. My code uses slf4j-log4j12 bridge. In maven central compile dependencies for slf4j-log4j shows log4j at version 1.2.17 with updates column showing 2.8.1.

So I tried following in build.gradle with the hope that log4j-api-2.8.1 would be used in place of log4j-1.2.17 which is pulled by default. But that doesn't seem to be working. I still see log4j-1.2.17 in the dependent jars.

So I wanted to ask, is this something that is not allowed at all? I.e. there is no slf4j-log4j bridge to log4j 2.8.1 version or for that matter 2.x version? Essentially I should migrate my code to use log4j-api-2.8.1. Or am I missing something here?

dependencies {
    compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.8.1'
    compile group: 'org.slf4j', name: 'slf4j-log4j12', version: '1.7.25'   
}

Solution

  • slf4j-log4j12 is a binding for log4j version 1.2. But you need log4j version 2 (log4j2) binding, which is named log4j-slf4j-impl.

    To use slf4j along with log4j2, you will require:

    • log4j-api (2.8.1)
    • log4j-core (2.8.1)
    • log4j-slf4j-impl (2.8.1)
    • slf4j-api (1.7.25)

    If you have any implementation and/or dependency over log4j version 1.2, you will also require:

    • log4j-1.2-api (2.8.1)

    However, you should not include following dependencies in any case:

    • log4j-to-slf4j (2.x)
    • log4j (1.2.x)