views:

185

answers:

4

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.

A: 

You can try to change the order on which the libraries are loaded by editing your classpath or to find a version which works with both in order to put it at the beginning of the classpath.

If you want to disable log4j, you can create for example a file named log4j.properties with the following content:

log4j.rootLogger=OFF

Now, you need to start your application by setting the log4j.configuration java variable :

java -Dlog4j.configuration=file:pathTo/log4j.properties my.app.Launcher
Laurent
Will disabling the root logger prevent `twitter4j.internal.logging.Log4JLogger.info` from invoking the (missing) method `org.apache.log4j.Logger.info(Ljava/lang/String;)V`? It may help, or it may not, depending on whetherLog4JLogger tests `isInfoEnabled()` before calling `info`.
Christian Semrau
+2  A: 

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.

Sijin
oddly twitter4j seems to be using org.slf4j's nlog4j rather than the apache log4j http://github.com/yusuke/twitter4j/blob/master/twitter4j-core/pom.xml
matt b
A: 

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.

Edward Mazur
A: 

Thanks a lot! it seems helped me right now after struggling with it almost full day

Shlomo