title: How to configure log4j2 for a web application in Tomcat 8?
body: <p>I'm deploying a web service as a web app (war) over Tomcat 8.0.24. Application jars have already been tested and they work fine. Now for configuring and testing log4j purposes I provoked a runtime error (no db connected). </p>
  
  <p>I'm trying to set log4j2 for application logging only (not for tomcat) and I'm using Netbeans 8.0.2 to build war.</p>
  
  <p>I have included following jars in classpath:</p>
  
  <pre><code>log4j-api-2.8.jar
  log4j-core-2.8.jar
  log4j-web-2.8.jar
  log4j-jcl-2.8.jar   
  commons-logging.jar 
  </code></pre>
  
  <p>And log4j2.xml in WEB-INF, with only root logger configured to catch everything coming from web app:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration strict="true" status="TRACE"&gt;
    &lt;Properties&gt;
      &lt;Property name="filename"&gt;C:\logs\Myapp.log&lt;/Property&gt;
    &lt;/Properties&gt;
    &lt;Appenders&gt;
  
      &lt;Appender type="Console" name="Console" target="SYSTEM_OUT"&gt;
        &lt;Layout type="PatternLayout"&gt;
          &lt;Pattern&gt;%d{HH:mm:ss.SSS} - %-5level %logger - %msg%n&lt;/Pattern&gt;
        &lt;/Layout&gt;
      &lt;/Appender&gt;
      &lt;Appender type="File" name="FileAppender" fileName="${filename}" append="true" immediateFlush="true"&gt;
        &lt;Layout type="PatternLayout"&gt;
          &lt;Pattern&gt;%d %p %logger -%C- %m%n&lt;/Pattern&gt;
        &lt;/Layout&gt;
      &lt;/Appender&gt;
    &lt;/Appenders&gt;
    &lt;Loggers&gt;
      &lt;Root level="ERROR"&gt;
        &lt;AppenderRef ref="Console"/&gt;
        &lt;AppenderRef ref="FileAppender" level="WARN"/&gt;
      &lt;/Root&gt;
    &lt;/Loggers&gt;
   &lt;/Configuration&gt;
  </code></pre>
  
  <p>I have also configured catalina.properties, just in case, to override default jarsToSkip: </p>
  
  <pre><code>tomcat.util.scan.StandardJarScanFilter.jarsToScan=log4j-core*.jar,log4j-taglib*.jar,log4j-api*.jar,log4j-web*.jar,log4j-jcl*.jar`
  </code></pre>
  
  <p>I believe log4j is being properly initialized as catalina*.log states, due to status="TRACE":</p>
  
  <pre><code>2017-02-08 14:06:52,355 http-nio-8080-exec-8 DEBUG Log4jServletContextListener ensuring that Log4j starts up properly.
  2017-02-08 14:06:52,357 http-nio-8080-exec-8 DEBUG Log4jServletFilter initialized.
  </code></pre>
  
  <p>And also because log file is created.</p>
  
  <p>However, all runtime error messages coming from application (web service jar) are ending into catalina*.log instead of file appender I have configured. Besides, those error messages in catalina*.log are not following any pattern defined in Appenders' definitions, so it basically seems like log4j2 is being ignored.</p>
  
  <p>What am I doing wrong? </p>