title: How to setup Log4j2 for an application deployed in WildFly 9?
body: <p>When I test my application with JUnit, it is printing the log as specified by layout pattern in <code>log4j2.xml</code>, but when I deploy my application
  in WildFly 9, I am no more getting the same format. Even the log level in Log4j2 is also not reflecting while deployed in server.</p>
  
  <p>JUnit log example:</p>
  
  <blockquote>
    <p>2016-02-15 11:14:16,314 DEBUG <em>[main]</em> <strong>b.t.r.c.XAPool</strong> - a connection's
    state changed to IN_POOL, notifying a thread eventually waiting for a
    connection</p>
  </blockquote>
  
  <p>Server log example:</p>
  
  <blockquote>
    <p>11:11:33,796 INFO  <strong>[org.quartz.core.QuartzScheduler]</strong> <em>(ServerService
    Thread Pool -- 89)</em> Scheduler
    quartzScheduler_$_anindya-ubuntu1455514892022 started.</p>
  </blockquote>
  
  <p>Log4j2.xml:</p>
  
  <pre><code>&lt;Configuration status="WARN" name="myapp" monitorInterval="5"&gt;
      &lt;Appenders&gt;
          &lt;RollingFile name="RollingFile" fileName="${myapp.log-dir}/myapp.log"
                       filePattern="${myapp.log-dir}/$${date:yyyy-MM}/myapp-%d{MM-dd-yyyy}-%i.log"&gt;
              &lt;PatternLayout&gt;
                  &lt;Pattern&gt;%d %p %c{1.} [%t] %m%n&lt;/Pattern&gt;
              &lt;/PatternLayout&gt;
              &lt;Policies&gt;
                  &lt;OnStartupTriggeringPolicy /&gt;
                  &lt;SizeBasedTriggeringPolicy size="25 MB"/&gt;
              &lt;/Policies&gt;
              &lt;DefaultRolloverStrategy max="100"&gt;
                  &lt;Delete basePath="${myapp.log-dir}" maxDepth="2"&gt;
                      &lt;IfFileName glob="*/myapp-*.log"&gt;
                          &lt;IfLastModified age="7d"&gt;
                              &lt;IfAny&gt;
                                  &lt;IfAccumulatedFileSize exceeds="1 GB" /&gt;
                                  &lt;IfAccumulatedFileCount exceeds="1" /&gt;
                              &lt;/IfAny&gt;
                          &lt;/IfLastModified&gt;
                      &lt;/IfFileName&gt;
                  &lt;/Delete&gt;
              &lt;/DefaultRolloverStrategy&gt;
          &lt;/RollingFile&gt;
      &lt;/Appenders&gt;
      &lt;Loggers&gt;
          &lt;Logger name="com.company.myapp" level="trace" additivity="false"&gt;
              &lt;AppenderRef ref="RollingFile"/&gt;
          &lt;/Logger&gt;
          &lt;Root level="info"&gt;
              &lt;AppenderRef ref="RollingFile"/&gt;
          &lt;/Root&gt;
      &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  
  <p>While starting the server, I am providing below starup properties as JAVA_OPTS:</p>
  
  <blockquote>
    <p>export JAVA_OPTS="$JAVA_OPTS -Dspring.profiles.active='qa'
    -Dlog4j.configurationFile=/home/anindya/1.0/log4j2.xml -myapp.log-dir=/home/anindya/log -Dorg.jboss.logging.provider=log4j"</p>
  </blockquote>
  
  <p>I have no specific setup in <code>web.xml</code> as it is Servlet 3.1 container. But I have a <code>jboss-deployment-structure.xml</code> in my <code>WEB-INF</code> as below:</p>
  
  <pre><code>&lt;jboss-deployment-structure xmlns="urn:jboss:deployment-structure:1.2"&gt;
      &lt;deployment&gt;
          &lt;!-- Exclusions allow you to prevent the server from automatically adding some dependencies --&gt;
          &lt;exclusions&gt;
              &lt;module name="org.apache.logging.log4j" /&gt;
          &lt;/exclusions&gt;
      &lt;/deployment&gt; 
  &lt;/jboss-deployment-structure&gt;
  </code></pre>
  
  <p>And finally, here are my classpath dependencies (only the relevant parts are mentioned here):</p>
  
  <ul>
  <li>hibernate-5.0.7.Final dependencies  </li>
  <li>jbpm-6.3.0.Final dependencies    </li>
  <li>spring-4.2.4.RELEASE dependencies    </li>
  <li>commons-logging-1.2.jar       </li>
  <li>log4j-1.2-api-2.5.jar </li>
  <li>log4j-api-2.5.jar    </li>
  <li>log4j-core-2.5.jar          </li>
  <li>log4j-jcl-2.5.jar       </li>
  <li>log4j-slf4j-impl-2.5.jar         </li>
  <li>log4j-web-2.5.jar                 </li>
  <li>jboss-logging-3.3.0.Final.jar</li>
  </ul>
  
  <p>With all of the above setup, I am still not able to configure Log4j2 in WildFly environment according to my <code>log4j2.xml</code>. Can someone please help?</p>
  
  <p>NOTE: I am running WildFly in standalone mode and I would like to avoid using <code>jboss-cli</code>.</p>