2

After upgrading existing app from Grails 1.3.7 to Grails 2.0.4 (tried 2.0.3 also) I got some kind of slf4j and log4j conflict. Seems that

  • log4j tries to write to using commons-logging
  • commons-logging write to slf4j
  • but slf4j logger appender uses log4j

Circular reference. And java.lang.StackOverflowError as a result.

java.lang.StackOverflowError
    at org.apache.log4j.PatternLayout.format(PatternLayout.java:500)
    at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
    at org.apache.log4j.Category.callAppenders(Category.java:206)
    at org.apache.log4j.Category.forcedLog(Category.java:391)
    at org.apache.log4j.Category.log(Category.java:856)
    at org.slf4j.impl.GrailsLog4jLoggerAdapter.logMessage(GrailsLog4jLoggerAdapter.java:191)
    at org.slf4j.impl.GrailsLog4jLoggerAdapter.error(GrailsLog4jLoggerAdapter.java:166)
    at org.apache.commons.logging.impl.SLF4JLog.error(SLF4JLog.java:213)
    at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
    at org.apache.log4j.Category.callAppenders(Category.java:206)
    at org.apache.log4j.Category.forcedLog(Category.java:391)
    at org.apache.log4j.Category.log(Category.java:856)
    at org.slf4j.impl.GrailsLog4jLoggerAdapter.logMessage(GrailsLog4jLoggerAdapter.java:191)
    at org.slf4j.impl.GrailsLog4jLoggerAdapter.error(GrailsLog4jLoggerAdapter.java:166)
    at org.apache.commons.logging.impl.SLF4JLog.error(SLF4JLog.java:213)
    at org.apache.log4j.AppenderSkeleton.doAppend(AppenderSkeleton.java:251)
    at org.apache.log4j.helpers.AppenderAttachableImpl.appendLoopOnAppenders(AppenderAttachableImpl.java:66)
    at org.apache.log4j.Category.callAppenders(Category.java:206)
    at org.apache.log4j.Category.forcedLog(Category.java:391)
    at org.apache.log4j.Category.log(Category.java:856)
    at org.slf4j.impl.GrailsLog4jLoggerAdapter.logMessage(GrailsLog4jLoggerAdapter.java:191)
    at org.slf4j.impl.GrailsLog4jLoggerAdapter.error(GrailsLog4jLoggerAdapter.java:166)
    ...

Seems that log4j logs to commons-logging, commons-loggin

I tried to exclude log4j from dependencies, and use log4j-over-slf4j as a replaicement but some Grails classes have direct Log4J usage:

java.lang.NoClassDefFoundError: org/apache/log4j/LogManager
    at org.slf4j.impl.GrailsSlf4jLoggerFactory.getLogger(GrailsSlf4jLoggerFactory.java:43)
    at org.slf4j.LoggerFactory.getLogger(LoggerFactory.java:253)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:156)
    at org.apache.commons.logging.impl.SLF4JLogFactory.getInstance(SLF4JLogFactory.java:132)
    at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:272)

And I can't exclude slf4j, because it's used by standard Grails plugins, like Resources plugin.

Btw, I never had such situation before, with other Grails 2.0.3 projects. Seems that it's something with configuration or dependencies specific only for current application, but I can't find anything unusual.

Anyone had same issue?

2 Answers 2

3

Fixed by uncommenting default appender:

appenders {
    console name:'stdout', layout:pattern(conversionPattern: '%c{2} %m%n')
}

Working now, but it's weird

0

I had the same StackOverflowError . It occurred when Grails tried to log a quite different exception during the start of my application. So the problem has something to do with Grails logging exceptions.

I fixed it by commenting out this line in my log4j configuration (in Config.groovy):

error stdout: "StackTrace"

After that the StackOverflowError disappeared and I could see the underlying exception.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.