title: How to disable log4j in web applications (turn off WARN messages)
body: <p><strong>In short:</strong> 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</p>
  
  <pre><code>log4j:WARN No appenders could be found for logger (org.apache.activemq.transport.WireFormatNegotiator).
  log4j:WARN Please initialize the log4j system properly.
  </code></pre>
  
  <p>and prevents a clean shutdown throwing errors like</p>
  
  <pre><code>Exception in thread "InactivityMonitor WriteCheck" java.lang.NullPointerException
  Exception in thread "InactivityMonitor ReadCheck" at java.util.TimerThread.run(Unknown Source) java.lang.NullPointerException
  </code></pre>
  
  <p><strong>The details:</strong></p>
  
  <p>I am writing a Tomcat web application which shall use Apache ActiveMQ. Aside from <em>activemq-all-5.5.1.jar</em> I had to put the following libraries on the class path to get rid of classpath issues:</p>
  
  <ul>
  <li>log4j-1.2.15.jar</li>
  <li>slf4j-api-1.5.11.jar</li>
  <li>slf4j-log4j12-1.5.11.jar</li>
  </ul>
  
  <p>Now my application starts printing warnings like that one above. There is <a href="https://activemq.apache.org/log4j-warn-no-appenders-could-be-found-for-logger.html" rel="nofollow noreferrer" title="Apache ActiveMQ ™ -- log4j-WARN No appenders could be found for logger">a link on the Apache ActiveMQ web site</a>, but unfortunately it’s broken, and <a href="https://wiki.apache.org/logging-log4j/" rel="nofollow noreferrer">Log4j wiki</a> is offline.</p>
  
  <p>I tried to create a file named <em>log4j.xml</em> as described <a href="https://stackoverflow.com/questions/1244487/how-do-i-turn-logging-off-using-log4j" title="java - How do I turn logging off using log4j? - Stack Overflow">here</a> and put it in the <em>WEB-INF/</em> 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. <em>WEB-INF/classes/</em>). I also tried the same adding XML headers to the file as I saw <a href="https://stackoverflow.com/questions/2619160/sample-xml-configuration-for-log4j-have-a-main-java-application-and-want-to-w" title="Sample xml configuration for log4j, have a &#39;main&#39; java application and want to write to file - Stack Overflow">here</a>. None of them works in either location. I read elsewhere that one has to pass the location by passing the <code>-Dlog4j.configuration=</code> parameter to the JVM, but that cannot be used in web application context. A <a href="http://www.avajava.com/tutorials/lessons/how-do-i-initialize-log4j-in-a-web-application.html" rel="nofollow noreferrer" title="How do I initialize Log4J in a web application? - Web Tutorials - avajava.com">Log4j for web application tutorial</a> shows how to configure it using <em>web.xml</em>, but that requires the library to contain a class which extends <code>HttpServlet</code>. I guess there isn’t such a class in Active MQ, and even if, how would I find it?</p>
  
  <p>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?</p>
  
  <p>Which is the most simple way to cleanly swich off this logger as long as I don’t need it?</p>