Grails 2.5.4 does not log anything when running with run-app after upgrading log4j

191 Views Asked by At

I am trying to upgrade the version of log4j in my grails 2.5.4 application from 1.2.17 to 2.17.2. I am able to build and deploy the war and have all the logs work as expected, but the app does not log anything when running with grails run-app locally.

To upgrade the version, I made the following changes to BuildConfig.groovy:

inherits("global") {
        excludes "grails-plugin-log4j", "log4j"
    }
    dependencies {

        runtime 'org.apache.logging.log4j:log4j-core:2.17.2'
        runtime 'org.apache.logging.log4j:log4j-api:2.17.2'
        runtime 'org.apache.logging.log4j:log4j-jcl:2.17.2'
        runtime 'org.apache.logging.log4j:log4j-slf4j-impl:2.17.2'
        runtime 'org.apache.logging.log4j:log4j-1.2-api:2.17.2'

log4j2.properties:

rootLogger.level = INFO
rootLogger.additivity = false
rootLogger.appenderRefs = stdout
rootLogger.appenderRef.stdout.ref = STDOUT

appender.console.type = Console
appender.console.name = STDOUT
appender.console.layout.type = PatternLayout
appender.console.layout.pattern = %d [%t] %-5p %c{2} %x %m %n 

If I remove the log4j-1.2-api dependency, the logs work locally with run-app but the app is unable to start when deploying the war. The primary error log is:

Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Level
1

There are 1 best solutions below

1
On

Using Log4j 2.17.1 appears to have resolved this.