slf4j
在将现有应用程序从 Grails 1.3.7 升级到 Grails 2.0.4(也尝试过 2.0.3)后,我遇到了一些log4j
冲突。看来
- log4j 尝试使用 commons-logging 写入
- 公共日志写入 slf4j
- 但是 slf4j logger appender 使用 log4j
循环参考。java.lang.StackOverflowError
结果。
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)
...
似乎 log4j 记录到 commons-logging、commons-loggin
我试图从依赖项中排除 log4j,并log4j-over-slf4j
用作替换,但一些 Grails 类直接使用 Log4J:
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)
而且我不能排除 slf4j,因为它被标准 Grails 插件使用,比如 Resources 插件。
顺便说一句,在其他 Grails 2.0.3 项目中,我以前从未遇到过这种情况。似乎它具有特定于当前应用程序的配置或依赖关系,但我找不到任何不寻常的东西。
有人有同样的问题吗?