In short: How can I configure some Log4j logger in a third-party jar which is used in a web application so that it stops writing out warnings like
log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.WireFormatNegotiator).
log4j:WARN Please initialize the log4j system properly.
and prevents a clean shutdown throwing errors like
Exception in thread "InactivityMonitor WriteCheck" java.lang.NullPointerException
Exception in thread "InactivityMonitor ReadCheck" at java.util.TimerThread.run(Unknown Source) java.lang.NullPointerException
The details:
I am writing a Tomcat web application which shall use Apache ActiveMQ. Aside from activemq-all-5.5.1.jar I had to put the following libraries on the class path to get rid of classpath issues:
- log4j-1.2.15.jar
- slf4j-api-1.5.11.jar
- slf4j-log4j12-1.5.11.jar
Now my application starts printing warnings like that one above. There is a link on the Apache ActiveMQ web site, but unfortunately it’s broken, and Log4j wiki is offline.
I tried to create a file named log4j.xml as described here and put it in the WEB-INF/ directory (where I would expect it to belong) but I also tried to put it in the “default package” with my source code (i.e. WEB-INF/classes/). I also tried the same adding XML headers to the file as I saw here. None of them works in either location. I read elsewhere that one has to pass the location by passing the -Dlog4j.configuration=
parameter to the JVM, but that cannot be used in web application context. A Log4j for web application tutorial shows how to configure it using web.xml, but that requires the library to contain a class which extends HttpServlet
. I guess there isn’t such a class in Active MQ, and even if, how would I find it?
Perhaps I am barking up the totally wrong tree and I do not have to configure Log4j itself, but instead Slf4j which then will silently configure Log4j for me?
Which is the most simple way to cleanly swich off this logger as long as I don’t need it?