使用 log4j 的多个库

发布于 2024-09-03 09:32:54 字数 928 浏览 1 评论 0原文

我正在编写一个小型 Java 应用程序,并且在使用 log4j 时遇到了一些问题,这似乎是由多个独立库试图同时使用它引起的:

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.log4j.Logger.info(Ljava/lang/String;)V
    at twitter4j.internal.logging.Log4JLogger.info(Log4JLogger.java:85)
    at twitter4j.internal.logging.Logger.<clinit>(Logger.java:72)
    at twitter4j.http.BasicAuthorization.<clinit>(BasicAuthorization.java:43)
    at twitter4j.http.AuthorizationFactory.getBasicAuthorizationInstance(AuthorizationFactory.java:66)
    at twitter4j.TwitterStreamFactory.getInstance(TwitterStreamFactory.java:121)
    at org.voltdb.twitter.drivers.Collect.main(Collect.java:13)

我正在使用的两个库是 Twitter4JVoltDB。两者都是 JAR 的形式。如果我单独使用其中任何一个,我都不会遇到这个问题;两者都可以单独工作。

如果这可以解决问题,则禁用任一库的 log4j 组件是可以接受的。

I'm writing a small Java application and having some trouble with log4j that appears to be caused by multiple, independent libraries trying to use it simultaneously:

Exception in thread "main" java.lang.NoSuchMethodError: org.apache.log4j.Logger.info(Ljava/lang/String;)V
    at twitter4j.internal.logging.Log4JLogger.info(Log4JLogger.java:85)
    at twitter4j.internal.logging.Logger.<clinit>(Logger.java:72)
    at twitter4j.http.BasicAuthorization.<clinit>(BasicAuthorization.java:43)
    at twitter4j.http.AuthorizationFactory.getBasicAuthorizationInstance(AuthorizationFactory.java:66)
    at twitter4j.TwitterStreamFactory.getInstance(TwitterStreamFactory.java:121)
    at org.voltdb.twitter.drivers.Collect.main(Collect.java:13)

The two libraries I'm using are Twitter4J and VoltDB. Both are in the form of JARs. If I use either in isolation, I don't run into this problem; both work fine on their own.

It would be acceptable to disable the log4j component of either library if this fixed the problem.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

热鲨 2024-09-10 09:32:54

您确定您使用的是两个库所需的正确版本的 log4j 吗?您的错误消息似乎表明 log4j 版本不正确。

Are you sure you're using the right version of log4j as required by both libraries? Your error message seems to indicate in incorrect log4j version IMO.

笑梦风尘 2024-09-10 09:32:54

我遇到了对 Twitter4J 日志记录问题的回复,其中显示了如何禁用日志记录:

-Dtwitter4j.loggerFactory=twitter4j.internal.logging.StdOutLoggerFactory

添加此属性使异常消失。

I came across a reply to a Twitter4J logging problem that shows how to disable logging:

-Dtwitter4j.loggerFactory=twitter4j.internal.logging.StdOutLoggerFactory

Adding this property made the exception disappear.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文