tags:

views:

54

answers:

1

Hi,

I'm quite new with Tomcat and Java in general. I'm deploying a Tomcat6 application and using the twitter4j library to make calls to Twitter.com. I've setup logging in Tomcat to be log4j using the following configuration:

log4j.rootLogger=ERROR, R 
log4j.appender.R=org.apache.log4j.RollingFileAppender
log4j.appender.R.File=${catalina.base}/logs/tomcat.log
log4j.appender.R.MaxFileSize=10MB 
log4j.appender.R.MaxBackupIndex=10 
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%p %t %c - %m%n

And all is good. However twitter4j is choosing to log every single thing it does. As a result I end up with a huge log file that tells me nothing. Is there something I'm missing? Has anyone here tried something similar? i.e. twitter4j and Tomcat, and has some insight on how to avoid all these logs:

[twitter4j.internal.logging.Logger]: Using class twitter4j.internal.logging.SLF4JLoggerFactory as logging factory.
[twitter4j.internal.http.HttpClientFactory]: Use twitter4j.internal.http.HttpClientImpl as HttpClient implementation.
[twitter4j.internal.http.HttpClientImpl]: Request: 
[twitter4j.internal.http.HttpClientImpl]: GET api.twitter.com/1/friends/ids.json?cursor=-1
[twitter4j.internal.http.HttpClientImpl]: X-Twitter-Client-URL:twitter4j.org/en/twitter4j-2.1.3-SNAPSHOT(build:e903c577fb3401b4c66037dfc477e73e6851e8e1).xml
[twitter4j.internal.http.HttpClientImpl]: X-Twitter-Client: Twitter4J
[twitter4j.internal.http.HttpClientImpl]: Accept-Encoding: gzip
[twitter4j.internal.http.HttpClientImpl]: User-Agent: twitter4j http://twitter4j.org//2.1.3-SNAPSHOT(build:e903c577fb3401b4c66037dfc477e73e6851e8e1)
[twitter4j.internal.http.HttpClientImpl]: X-Twitter-Client-Version:2.1.3-SNAPSHOT(build: e903c577fb3401b4c66037dfc477e73e6851e8e1)
[twitter4j.internal.http.HttpClientImpl]: Connection: close
[twitter4j.internal.http.HttpClientImpl]: Response: 
[twitter4j.internal.http.HttpClientImpl]: HTTP/1.1 200 OK
[twitter4j.internal.http.HttpClientImpl]: X-Runtime: 0.06539
[twitter4j.internal.http.HttpClientImpl]: ETag:"89c0c8cb8befe1371d08f1b6671b08de"-gzip
[twitter4j.internal.http.HttpClientImpl]: X-Transaction:1281584957-49704-11766
[twitter4j.internal.http.HttpClientImpl]: X-RateLimit-Limit: 20000
[twitter4j.internal.http.HttpClientImpl]: X-RateLimit-Remaining: 19999
[twitter4j.internal.http.HttpClientImpl]: Content-Length: 89
[twitter4j.internal.http.HttpClientImpl]: Expires: Tue, 31 Mar 1981 05:00:00 GMT
[twitter4j.internal.http.HttpClientImpl]: Last-Modified: Thu, 12 Aug 2010 03:49:17 GMT
[twitter4j.internal.http.HttpClientImpl]: X-RateLimit-Reset: 1281588557
[twitter4j.internal.http.HttpClientImpl]: X-RateLimit-Class: api_whitelisted
[twitter4j.internal.http.HttpClientImpl]: X-Revision: DEV
[twitter4j.internal.http.HttpClientImpl]: Set-Cookie: lang=en; path=

etc, etc, etc.

Thanks so much for any insight you might have. It's really driving me insane at the moment.

A: 

The logs you've pasted suggest that the pattern you've specified in your config isn't being applied (for example %p is log level, but the log level isn't in the output). That leads me to think that your log4j config isn't working.

Can you describe where the log4j properties file is, and where the log4j jar file is in your application?

Your log4j.properties should be at /WEB-INF/classes/log4j.properties, and the log4j.jar should be in /WEB-INF/lib.

Also looks like twitter4j is using SLF4j and not log4j. I think you just need to include the slf4j-logj12.jar library on the classpath as well to switch to the log4j implementation.

Brabster
I just tried your suggestions. The log4j.properties is at /WEB-INF/classes/log4j.properties, and the log4j.jar is at /web-inf/lib. I just added the slf4j-logj12.jar into /WEB-INF/lib. When I re-deployed the application I still got the same messages.This output is from catalina.out.
Roberto
The output from Tomcat.log (log4j) follows the properties file: > ERROR http-8080-6 org.apache.catalina.loader.WebappClassLoader - A web application appears to have started a thread named [Timer-2] but has failed to stop it. This is very likely to create a memory leak.> ERROR http-8080-6 org.apache.catalina.loader.WebappClassLoader - A web application appears to have started a thread named [Twitter Stream Handling Thread[Establishing connection]] but has failed to stop it. This is very likely to create a memory leak.Why does twitter4j print to stdout?
Roberto