Android 运行时异常“没有合适的日志实现”的可能原因是什么?与登录 3rd-party jar 有关吗?
我正在创建一个包含第三方 jar 的 Android 应用程序。该第三方 jar 使用内部日志记录,当我运行应用程序时,该日志记录无法初始化,并出现以下错误:“org.apache.commons.logging.LogConfigurationException:没有合适的日志实现”。
第 3 方 jar 似乎正在使用 org.apache.commons.logging 并依赖于 log4j,特别是 log4j-1.2.14.jar。我已将 log4j jar 打包到 Android 应用程序中。第三方 jar 与 log4j.xml 配置文件一起打包,我已尝试将其作为 XML 资源(也作为原始资源)打包到应用程序中。
“没有合适的 Log 实现”错误消息的描述性并不强,而且我对 Java 日志记录也没有立即熟悉。因此,我正在寻找问题的可能原因(我可能缺少哪些类或配置资源?),或者寻找一些调试技术,这些技术将导致更明确地说明问题的不同错误消息。我无权访问第 3 方 jar 的源代码。
这是异常堆栈跟踪。当我运行该应用程序时,只要第三方 jar 类之一尝试初始化其内部日志记录,我就会收到以下异常。
DEBUG/AndroidRuntime(15694): Shutting down VM
WARN/dalvikvm(15694): threadid=3: thread exiting with uncaught exception (group=0x4001b180)
ERROR/AndroidRuntime(15694): Uncaught handler: thread main exiting due to uncaught exception
ERROR/AndroidRuntime(15694): java.lang.ExceptionInInitializerError
ERROR/AndroidRuntime(15694): Caused by: org.apache.commons.logging.LogConfigurationException: No suitable Log implementation
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:842)
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:601)
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:333)
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:307)
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:645)
ERROR/AndroidRuntime(15694): at org.apache.commons.configuration.ConfigurationFactory.<clinit>(ConfigurationFactory.java:77)
I am creating an Android app that includes a third party jar. That third party jar utilizes internal logging that is failing to initialize when I run the app, with this error: "org.apache.commons.logging.LogConfigurationException: No suitable Log implementation".
The 3rd party jar appears to be using org.apache.commons.logging and to depend on log4j, specifically log4j-1.2.14.jar. I have packaged the log4j jar into the Android app. The third party jar was packaged with a log4j.xml configuration file, which I have tried packaging into the app as an XML resource (and also as a raw resource).
The "No suitable Log implementation" error message is not very descriptive, and I have no immediate familiarity with Java logging. So I am looking for likely causes of the problem (what class or configuration resources might I be missing?) or for some debugging technique that will result in a different error message that is more explicit about the problem. I do not have access to source code for the 3rd party jar.
Here is the exception stack trace. When I run the app, I get the following exception as soon as one of the third party jar classes attempts to initialize its internal logging.
DEBUG/AndroidRuntime(15694): Shutting down VM
WARN/dalvikvm(15694): threadid=3: thread exiting with uncaught exception (group=0x4001b180)
ERROR/AndroidRuntime(15694): Uncaught handler: thread main exiting due to uncaught exception
ERROR/AndroidRuntime(15694): java.lang.ExceptionInInitializerError
ERROR/AndroidRuntime(15694): Caused by: org.apache.commons.logging.LogConfigurationException: No suitable Log implementation
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.impl.LogFactoryImpl.discoverLogImplementation(LogFactoryImpl.java:842)
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.impl.LogFactoryImpl.newInstance(LogFactoryImpl.java:601)
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:333)
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.impl.LogFactoryImpl.getInstance(LogFactoryImpl.java:307)
ERROR/AndroidRuntime(15694): at org.apache.commons.logging.LogFactory.getLog(LogFactory.java:645)
ERROR/AndroidRuntime(15694): at org.apache.commons.configuration.ConfigurationFactory.<clinit>(ConfigurationFactory.java:77)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
研究 org.apache.commons.logging.impl.LogFactoryImpl 周围的逻辑可能会有所帮助,
可能有一种注入 Log 实现的方法。
http://google.com/codesearch/p?hl=en#CskViEIa27Y/src/org/apache/commons/logging/impl/LogFactoryImpl.java&l=762
http://google.com/codesearch /p?hl=en#CskViEIa27Y/src/org/apache/commons/logging/impl/LogFactoryImpl.java&l=883
It may help to study the logic around org.apache.commons.logging.impl.LogFactoryImpl
There's probably a way of injecting a Log implementation.
http://google.com/codesearch/p?hl=en#CskViEIa27Y/src/org/apache/commons/logging/impl/LogFactoryImpl.java&l=762
http://google.com/codesearch/p?hl=en#CskViEIa27Y/src/org/apache/commons/logging/impl/LogFactoryImpl.java&l=883