如何从JBoss AS 7.0.2.Final上的server.log中排除记录器类别

时间:2012-09-11 23:49:40

标签: java logging jboss7.x

我正在使用JBoss AS 7.0.2.Final,没有机会改变它。

我尝试配置standalone.xml,以便为不同的类别创建不同的日志文件。我的问题是:每个记录器的输出都在指定文件上正确附加,但也写在server.log文件中。

我的整个日志记录子系统配置:

<subsystem xmlns="urn:jboss:domain:logging:1.1">
    <console-handler name="CONSOLE" autoflush="true">
        <level name="INFO"/>
        <formatter>
            <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
        </formatter>
    </console-handler>
    <periodic-rotating-file-handler name="FILE" autoflush="true">
        <level name="INFO"/>
        <formatter>
            <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
        </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="REQUEST" autoflush="true">
        <level name="INFO"/>
        <formatter>
            <pattern-formatter pattern="%m%n"/>
        </formatter>
        <file path="/Logs/requests.log"/>
        <suffix value=".yyyy-MM-dd-HH"/>
        <append value="true"/>
    </periodic-rotating-file-handler>
    <periodic-rotating-file-handler name="ALARMS" autoflush="true">
        <level name="INFO"/>
        <formatter>
            <pattern-formatter pattern="%m%n"/>
        </formatter>
        <file path="/Logs/alarms.log"/>
        <suffix value=".yyyy-MM-dd-HH"/>
        <append value="true"/>
    </periodic-rotating-file-handler>
    <logger category="com.maucho.alarm" use-parent-handlers="false">
        <level name="INFO"/>
        <handlers>
            <handler name="ALARMS"/>
        </handlers>
    </logger>
    <logger category="com.maucho.request" use-parent-handlers="false">
        <level name="INFO"/>
        <handlers>
            <handler name="REQUEST"/>
        </handlers>
    </logger>
    <logger category="com.arjuna">
        <level name="WARN"/>
    </logger>
    <logger category="org.apache.tomcat.util.modeler">
        <level name="WARN"/>
    </logger>
    <logger category="sun.rmi">
        <level name="WARN"/>
    </logger>
    <logger category="com.hp.autopassj">
        <level name="WARN"/>
    </logger>
    <logger category="org.jboss.as.server.deployment">
        <level name="ERROR"/>
    </logger>
    <root-logger>
        <level name="INFO"/>
        <handlers>
            <handler name="CONSOLE"/>
            <handler name="FILE"/>
        </handlers>
    </root-logger>
</subsystem>

当启动AS时,standalone.xml文件被覆盖并替换没有属性use-parent-handlers =“false”的logger标记,没有任何内容,将行为设置为其默认值,use-parent-handlers =“true”:

<subsystem xmlns="urn:jboss:domain:logging:1.1">
    <console-handler name="CONSOLE" autoflush="true">
        <level name="INFO"/>
        <formatter>
            <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
        </formatter>
    </console-handler>
    <periodic-rotating-file-handler name="FILE" autoflush="true">
        <level name="INFO"/>
        <formatter>
            <pattern-formatter pattern="%d{HH:mm:ss,SSS} %-5p [%c] (%t) %s%E%n"/>
        </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="REQUEST" autoflush="true">
        <level name="INFO"/>
        <formatter>
            <pattern-formatter pattern="%m%n"/>
        </formatter>
        <file path="/Logs/requests.log"/>
        <suffix value=".yyyy-MM-dd-HH"/>
        <append value="true"/>
    </periodic-rotating-file-handler>
    <periodic-rotating-file-handler name="ALARMS" autoflush="true">
        <level name="INFO"/>
        <formatter>
            <pattern-formatter pattern="%m%n"/>
        </formatter>
        <file path="/Logs/alarms.log"/>
        <suffix value=".yyyy-MM-dd-HH"/>
        <append value="true"/>
    </periodic-rotating-file-handler>
    <logger category="com.maucho.alarm">
        <level name="INFO"/>
        <handlers>
            <handler name="ALARMS"/>
        </handlers>
    </logger>
    <logger category="com.maucho.request">
        <level name="INFO"/>
        <handlers>
            <handler name="REQUEST"/>
        </handlers>
    </logger>
    <logger category="com.arjuna">
        <level name="WARN"/>
    </logger>
    <logger category="org.apache.tomcat.util.modeler">
        <level name="WARN"/>
    </logger>
    <logger category="sun.rmi">
        <level name="WARN"/>
    </logger>
    <logger category="com.hp.autopassj">
        <level name="WARN"/>
    </logger>
    <logger category="org.jboss.as.server.deployment">
        <level name="ERROR"/>
    </logger>
    <root-logger>
        <level name="INFO"/>
        <handlers>
            <handler name="CONSOLE"/>
            <handler name="FILE"/>
        </handlers>
    </root-logger>
</subsystem>

文档很差,并说我只需要将参数use-parent-handlers =“false”,但它不起作用。

另外,我还将我的代码org.apache.log4j.Logger改为org.apache.commons.logging.Log与org.apache.commons.logging.LogFactory并且具有相同的结果,两个文件中的日志输出( /Logs/requests.log或/Logs/alarms.log AND server.log)。

我的参考资料: https://community.jboss.org/message/731527 http://commons.apache.org/logging/guide.html

1 个答案:

答案 0 :(得分:6)

这是一个非常老的线程,但以防万一有人正在寻找这个问题的解决方案。属性名称中有拼写错误,缺少's'。这是设置让它工作的属性 - 使用父处理程序**š** =假