title: Log4j2 with Jboss does not work
body: <p>I got a problem with <code>log4j2</code> and I'd like to understand what is the issue.
  I used to log with <code>log4j 1.2</code> on a webapp based on jsf and spring, and running on JBoss 7.1.2, and I am now trying to replace it with <code>log4j 2.8</code>, but it seems not to work.
  I cannot understand which is the problem, since from server logs it seems to find the log4j2.xml when it has problems, but it says nothing when it has got no syntax errors, but it also stop printing in console, so I think both it is finding that config file and not doing anything else.
  Maybe is better i show you the code instead of talking about it.
  I can't guess what is wrong, i followed apache instructions, many other examples, but still does not work.
  <br>
  <code>pom.xml</code>:</p>
  
  <pre><code>  &lt;dependency&gt;
      &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
      &lt;artifactId&gt;log4j-api&lt;/artifactId&gt;
      &lt;version&gt;2.8.1&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
      &lt;artifactId&gt;log4j-core&lt;/artifactId&gt;
      &lt;version&gt;2.8.1&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
      &lt;artifactId&gt;log4j-jul&lt;/artifactId&gt;
      &lt;version&gt;2.8.1&lt;/version&gt;
    &lt;/dependency&gt;
    &lt;dependency&gt;
      &lt;groupId&gt;org.apache.logging.log4j&lt;/groupId&gt;
      &lt;artifactId&gt;log4j-web&lt;/artifactId&gt;
      &lt;version&gt;2.8.1&lt;/version&gt;
    &lt;/dependency&gt;
  </code></pre>
  
  <p><code>jboss-deployment-structure.xml</code></p>
  
  <pre><code>&lt;exclusions&gt;
  [...]
          &lt;module name="org.apache.log4j" /&gt;
          &lt;module name="org.slf4j" /&gt;
          &lt;module name="org.apache.commons.logging"/&gt;
          &lt;module name="org.log4j"/&gt;  
          &lt;module name="org.jboss.logging"/&gt;
          &lt;module name='org.slf4j.impl' /&gt;
  &lt;/exclusions&gt;
  </code></pre>
  
  <p><code>web.xml</code>:</p>
  
  <pre><code>    &lt;context-param&gt;
          &lt;param-name&gt;log4jConfiguration&lt;/param-name&gt;
          &lt;param-value&gt;/WEB-INF/log4j2.xml&lt;/param-value&gt;
      &lt;/context-param&gt;
  </code></pre>
  
  <p>and also</p>
  
  <pre><code> &lt;listener&gt;
      &lt;listener-class&gt;org.springframework.web.util.Log4jConfigListener&lt;/listener-class&gt;
  &lt;/listener&gt;
  </code></pre>
  
  <p>and <code>log4j2.xml</code> under <code>WEB-INF</code> (it does find it since if I do syntax error it gives parsing error messages in console starting server)</p>
  
  <pre><code> &lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Configuration&gt;
    &lt;Properties&gt;
          &lt;Property name="layoutPattern"&gt;%d %-5p %c{1}:%L %m %n&lt;/Property&gt;
    &lt;/Properties&gt;
    &lt;Appenders&gt;
      &lt;File name="mainFileAppender" fileName="${webapp.root}/log/main.log"&gt;
          &lt;PatternLayout&gt;
              &lt;Pattern&gt;%d %d{Z} [%t] %-5p (%F:%L) - %m%n &lt;/Pattern&gt;
          &lt;/PatternLayout&gt;        
          &lt;/File&gt;
      &lt;File name="hibernateAppender" fileName="${webapp.root}/log/hibernate.log"&gt;
          &lt;PatternLayout&gt;
              &lt;Pattern&gt;%d %d{Z} [%t] %-5p (%F:%L) - %m%n &lt;/Pattern&gt;
          &lt;/PatternLayout&gt;
      &lt;/File&gt;
    &lt;/Appenders&gt;
  &lt;Loggers&gt;
      &lt;Logger name="org.hibernate.SQL" level="debug" includeLocation="true"&gt;
        &lt;AppenderRef ref="hibernateAppender"/&gt;
        &lt;AppenderRef ref="mainFileAppender"/&gt;
      &lt;/Logger&gt;
      &lt;Logger name="org.hibernate.type" level="trace" includeLocation="true"&gt;
        &lt;AppenderRef ref="hibernateAppender"/&gt;
      &lt;/Logger&gt;
      &lt;Logger name="com.example" level="trace"&gt;
          &lt;AppenderRef ref="mainFileAppender"/&gt;
      &lt;/Logger&gt;
      &lt;Root level="trace" includeLocation="true"&gt;
        &lt;AppenderRef ref="mainFileAppender"/&gt;
      &lt;/Root&gt;
  &lt;/Loggers&gt;
  &lt;/Configuration&gt;
  </code></pre>
  
  <p>and, in an example class loaded when I enter my web app</p>
  
  <blockquote>
    <p>public org.apache.logging.log4j.Logger logger = org.apache.logging.log4j.LogManager.getRootLogger();</p>
  </blockquote>
  
  <p><br>
  and inside the first called method <br></p>
  
  <blockquote>
    <p>logger.debug("Hi there");</p>
  </blockquote>
  
  <p>I also tried instantiating a normal logger with <code>LogManager.getLogger()</code></p>
  
  <p>Anyway I at least expected to find the log directory, but it is not being created.
  Can You please help me? It would really be appreciated.
  Thank You.</p>
  
  <p>Edit: Half solved;
  I cannot pass <code>${webapp.root}</code> nor <code>${sys:webapp.root}</code>, anyway I was interested in using <code>jboss.server.log.dir</code> variable and i solved using <code>${sys:jboss.server.log.dir}</code>
  Now the problem is that is not logging hibernate queries as log4j1.2 did, but I'm looking at configuration to see what is wrong, since it is able to log the logger when instantiated but nothing else.</p>