具有不同阈值的Log4J多个appender

时间:2011-12-30 17:21:12

标签: log4j

我正在尝试配置log4j以将所有日志记录事件发送到文件appender,并将ERROR或更高版本的事件记录到JMSAppender。但是,每当我将JMSAppender阈值设置为ERROR时,只会将错误或更高的值写入文件追加器。这是我的配置:

    <appender name="JBOSS" class="org.jboss.logging.appender.DailyRollingFileAppender">
            <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler" />
            <param name="File" value="${jboss.server.log.dir}/server.log" />
            <param name="Append" value="true" />

            <!-- Rollover at midnight each day -->
            <param name="DatePattern" value="'.'yyyy-MM-dd" />

            <layout class="org.apache.log4j.PatternLayout">
                    <!--
                            The default pattern: Date Priority [Category] Message\n
                            <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
                    -->

                    <!--
                            The full pattern: Date MS Priority [Category] (Thread:MDC) Message\n
                    -->
                    <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%X{TXID}) %m%n" />
            </layout>
    </appender>

    <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
            <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler" />
            <param name="File" value="${jboss.server.log.dir}/app.log" />
            <param name="Append" value="true" />
            <param name="Threshold" value="DEBUG" />
            <!-- Rollover at midnight each day -->
            <param name="DatePattern" value="'.'yyyy-MM-dd" />

            <layout class="org.apache.log4j.PatternLayout">
                    <!--
                            The default pattern: Date Priority [Category] Message\n
                            <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
                    -->

                    <!--
                            The full pattern: Date MS Priority [Category] (Thread:MDC) Message\n
                    -->
                    <param name="ConversionPattern" value="%d %-5r %-5p [%c] (%t:%X{TXID}) %m%n" />
            </layout>
    </appender>



    <appender name="TOPIC_APPENDER" class="org.apache.log4j.net.JMSAppender">
            <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler" />
            <param name="Threshold" value="ERROR">
            <param name="ProviderURL" value="jnp://SERVERX:1099/" />
            <param name="InitialContextFactoryName" value="org.jnp.interfaces.NamingContextFactory" />
            <param name="URLPkgPrefixes" value="org.jboss.naming:org.jnp.interfaces" />
            <param name="TopicConnectionFactoryBindingName" value="ClusteredConnectionFactory"/>
            <param name="TopicBindingName" value="errorLogTopic"/>
    </appender>

    <!-- Buffer events and log them asynchronously -->

    <appender name="ASYNC" class="org.apache.log4j.AsyncAppender">
            <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler" />
            <appender-ref ref="JBOSS" />
    </appender>

    <appender name="APP-ASYNC" class="org.apache.log4j.AsyncAppender">
            <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler" />
            <appender-ref ref="FILE" />
            <appender-ref ref="TOPIC_APPENDER" />
    </appender>



    <!-- ================ -->
    <!-- Limit categories -->
    <!-- ================ -->

     <!--
            This is the top of the logging configuration. APP events will not go
            to the JBoss logger.
    -->

    <category name="com.app.pkg" additivity="false">
            <priority value="DEBUG" />
            <appender-ref ref="APP-ASYNC" />
    </category>

    <root>
            <priority value="INFO" />
            <appender-ref ref="ASYNC" />
    </root>

提前致谢!

1 个答案:

答案 0 :(得分:0)

缺少JMSAppender阈值参数中的'/':

<param name="Threshold" value="ERROR">

应该是

<param name="Threshold" value="ERROR" />