如何在Wildfly 8上记录应用程序审核以分离文件 [英] How to log application auditing to separate file on Wildfly 8

查看:54
本文介绍了如何在Wildfly 8上记录应用程序审核以分离文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在Wildfly 8上运行的Java EE应用程序,我想在其中启用审核日志记录.使用InterceptorBinding和Interceptor,我可以捕获所有相关的API调用.

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.

我要做的是将这些审核调用写入单独的审核日志文件.我尝试使用logback并在此stackoverflow问题我终于做到了.第一个答复(即禁用系统日志记录)不起作用.但是,虽然此解决方案成功地将我的审核跟踪写入一个单独的文件,但所有其他日志记录都停止写入其默认文件,而仅输出到控制台.

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.

我要实现的是将所有常规日志记录默认情况下写入常规文件(即server.log),但将我自己的自定义审核日志消息存储在单独的文件中(每天滚动)的基础上,将旧文件重命名为写入的日期.

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).

这是使用Logback,log4j,Wildfly自己的日志系统,甚至是Wildfly CLI审核日志来完成的,只要它能达到目的并且以最小的开销就无关紧要.我现阶段正在考虑使用简单的输出流将其写入我自己的文件中,但是当有解决方案应该更有效地执行此操作时,这感觉是多余的.

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>

推荐答案

我终于通过修改Wildfly中的standalone.xml文件来实现了想要的目标.我添加了一个自定义文件处理程序和使用此文件处理程序的记录器.不需要自定义的logback实现或类似的东西.

I finally managed to achieve what I wanted by modifying the standalone.xml file in Wildfly. I added a custom file-handler and logger that uses this file-handler. No need for a custom logback implementation or anything like that.

    <subsystem xmlns="urn:jboss:domain:logging:2.0">
        <console-handler name="CONSOLE">
            <level name="INFO"/>
            <formatter>
                <named-formatter name="COLOR-PATTERN"/>
            </formatter>
        </console-handler>
        <periodic-rotating-file-handler name="FILE" autoflush="true">
            <formatter>
                <named-formatter name="PATTERN"/>
            </formatter>
            <file relative-to="jboss.server.log.dir" path="server.log"/>
            <suffix value=".yyyy-MM-dd"/>
            <append value="true"/>
        </periodic-rotating-file-handler>
        <periodic-rotating-file-handler name="MYHANDLER" autoflush="true">
            <formatter>
                <named-formatter name="PATTERN"/>
            </formatter>
            <file relative-to="jboss.server.log.dir" path="application-audit.log"/>
            <suffix value=".yyyy-MM-dd"/>
            <append value="true"/>
        </periodic-rotating-file-handler>
        <logger category="com.mycompany.myapplication">
            <level name="INFO"/>
            <handlers>
                <handler name="MYHANDLER"/>
            </handlers>
        </logger>
        <logger category="com.arjuna">
            <level name="WARN"/>
        </logger>
        <logger category="org.apache.tomcat.util.modeler">
            <level name="WARN"/>
        </logger>
        <logger category="org.jboss.as.config">
            <level name="DEBUG"/>
        </logger>
        <logger category="sun.rmi">
            <level name="WARN"/>
        </logger>
        <logger category="jacorb">
            <level name="WARN"/>
        </logger>
        <logger category="jacorb.config">
            <level name="ERROR"/>
        </logger>
        <logger category="org.jboss.security">
            <level name="TRACE"/>
        </logger>
        <root-logger>
            <level name="INFO"/>
            <handlers>
                <handler name="CONSOLE"/>
                <handler name="FILE"/>
            </handlers>
        </root-logger>
        <formatter name="PATTERN">
            <pattern-formatter pattern="%d{yyyy-MM-dd HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
        </formatter>
        <formatter name="COLOR-PATTERN">
            <pattern-formatter pattern="%K{level}%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
        </formatter>
    </subsystem>

这篇关于如何在Wildfly 8上记录应用程序审核以分离文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆