title: How to log application auditing to separate file on Wildfly 8
body: <p>I have a Java EE application running on Wildfly 8 in which I want to enable audit logging. Using an InterceptorBinding and Interceptor I am able to catch all relevant API calls.</p>
  
  <p>What I want to do is to write these audit calls to a separate audit log file. I tried implementing this using logback, and with the help of the second answer in <a href="https://stackoverflow.com/questions/21846329/override-logging-in-wildfly/26342226#26342226">this stackoverflow question</a> I finally managed to do this. The first reply, i.e. disabling the system logging, did not work. However, while this solution successfully writes my audit trace to a separate file, all other logging stopped being written to their default files and was only output into the console.</p>
  
  <p>What I want to achieve is to have all regular logging written to the regular file (i.e. server.log) as it is by default, but to have my own custom audit log messages in a separate file (also rolling on a daily basis, renaming the old file to the date it was written).</p>
  
  <p>Whether this is done with Logback, log4j, Wildfly's own logging system or even the Wildfly CLI audit log, is irrelevant as long as it achieves the purpose, with minimal overhead. I am at this stage considering writing it into my own file with a simple outputstream, but that feels rather superfluous when there are solutions that should do this much more efficiently.</p>
  
  <p>This is what my logback file looks like:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;configuration&gt;
      &lt;appender name="AUDIT-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;file&gt;/Applications/wildfly/standalone/log/logback/audit/audit.log&lt;/file&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;FileNamePattern&gt;logFile.%d{yyyy-MM-dd}.log&lt;/FileNamePattern&gt;
          &lt;/rollingPolicy&gt;
          &lt;encoder&gt;
              &lt;pattern&gt;%d{HH:mm:ss.SSS}: - %msg%n&lt;/pattern&gt;
          &lt;/encoder&gt;
      &lt;/appender&gt;
      &lt;appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"&gt;
          &lt;File&gt;/Applications/wildfly/standalone/log/logback/server.log&lt;/File&gt;
          &lt;rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"&gt;
              &lt;FileNamePattern&gt;logFile.%d{yyyy-MM-dd}.log&lt;/FileNamePattern&gt;
          &lt;/rollingPolicy&gt;
          &lt;encoder&gt;
              &lt;Pattern&gt;%d{HH:mm:ss.SSS} %-4relative [%thread] %-5level %logger{35} - %msg%n&lt;/Pattern&gt;
          &lt;/encoder&gt;
      &lt;/appender&gt;
      &lt;logger name="audit" level="INFO" additivity="false"&gt;
          &lt;appender-ref ref="AUDIT-FILE"/&gt;
      &lt;/logger&gt;
      &lt;logger name="org.jboss.resteasy.core.ExceptionHandler" level="ALL"&gt;
          &lt;appender-ref ref="FILE" /&gt;
      &lt;/logger&gt;
      &lt;root level="ALL"&gt;
          &lt;appender-ref ref="FILE"/&gt;
      &lt;/root&gt;
  &lt;/configuration&gt;
  </code></pre>