Log4j2抛出NoSuchMethodError

时间:2014-07-24 09:58:33

标签: java log4j log4j2

我已从log4j2 2.0-beta9升级到2.0 log4j-corelog4j-api

我的应用程序以前运行正常,现在我收到以下错误:

Caused by: java.lang.NoSuchMethodError: org.apache.logging.log4j.core.Logger.log(Lorg/apache/logging/log4j/Marker;Ljava/lang/String;Lorg/apache/logging/log4j/Level;Lorg/apache/logging/log4j/message/Message;Ljava/lang/Throwable;)V
    at org.apache.log4j.Category.forcedLog(Category.java:336)
    at org.apache.log4j.Category.log(Category.java:423)
    at com.mchange.v2.log.log4j.Log4jMLog$Log4jMLogger.log(Log4jMLog.java:171)
    at com.mchange.v2.log.log4j.Log4jMLog$Log4jMLogger.log(Log4jMLog.java:183)
    at com.mchange.v2.cfg.MConfig.dumpToLogger(MConfig.java:101)
    at com.mchange.v2.cfg.MConfig.dumpToLogger(MConfig.java:98)
    at com.mchange.v2.cfg.MConfig$CSManager.recreateFromKey(MConfig.java:154)
    at com.mchange.v1.cachedstore.NoCleanupCachedStore.find(NoCleanupCachedStore.java:63)

这里可能有什么问题?为什么log4j失败了?

也许我必须从c3p0重定向日志记录?如何在log4j2中编写以下语句?

com.mchange.v2.log.MLog=com.mchange.v2.log.log4j.Log4jMLog

我发现以下语句将阻止c3p0日志记录,因此是我当前的解决方法:

System.setProperty("com.mchange.v2.log.MLog", "com.mchange.v2.log.FallbackMLog");

但是我想将日志重定向到log4j2,所以仍然在寻找解决方案。

2 个答案:

答案 0 :(得分:0)

更新:在撰写本文时,最新版本是Log4j 2.6.2。哪个是无垃圾的,所以如果你还在旧版本上请升级。

关于错误:您还记得将适配器模块(log4j-1.2-api-2.0-beta9.jar)从beta9升级到2.0吗?

答案 1 :(得分:0)

是的,测试版有这个问题。将其升级到2.X