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.
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 this stackoverflow question 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.
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).
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.
This is what my logback file looks like:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="AUDIT-FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/Applications/wildfly/standalone/log/logback/audit/audit.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>logFile.%d{yyyy-MM-dd}.log</FileNamePattern>
</rollingPolicy>
<encoder>
<pattern>%d{HH:mm:ss.SSS}: - %msg%n</pattern>
</encoder>
</appender>
<appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">
<File>/Applications/wildfly/standalone/log/logback/server.log</File>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<FileNamePattern>logFile.%d{yyyy-MM-dd}.log</FileNamePattern>
</rollingPolicy>
<encoder>
<Pattern>%d{HH:mm:ss.SSS} %-4relative [%thread] %-5level %logger{35} - %msg%n</Pattern>
</encoder>
</appender>
<logger name="audit" level="INFO" additivity="false">
<appender-ref ref="AUDIT-FILE"/>
</logger>
<logger name="org.jboss.resteasy.core.ExceptionHandler" level="ALL">
<appender-ref ref="FILE" />
</logger>
<root level="ALL">
<appender-ref ref="FILE"/>
</root>
</configuration>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…