Log4j2的FailoverAppender错误:追加程序故障转移没有与元素故障转移匹配的参数 [英] Log4j2's FailoverAppender Error: appender Failover has no parameter that matches element Failovers

查看:295
本文介绍了Log4j2的FailoverAppender错误:追加程序故障转移没有与元素故障转移匹配的参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用log4j 2.1编译spring 3.2.9 Web应用程序时,该错误出现在控制台中:

When I compile my spring 3.2.9 web application using log4j 2.1, this error appears in the console:

2015-02-02 12:08:25,213 ERROR appender Failover has no parameter that matches element Failovers

我了解的是,元素故障转移"在元素故障转移"内不存在,对吗?为什么会这样?我没有看到什么问题,因为我的配置与相同log4j2手册.

What I understand is that the element "Failovers" does not exist inside the element "Failover", right? Why would this happen? I don't see whats wrong since I have the same configuration as the log4j2 manual.

我的log4j2.xml中具有以下配置:

I have this configuration in my log4j2.xml:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration name="vcr-log4j2-config" status="debug">
    <Appenders>
        <Console name="STDOUT" target="SYSTEM_OUT">
            <PatternLayout>
                <Pattern>[%d{ISO8601}] %c [%C{1}] - %p: %m%n</Pattern>
            </PatternLayout>
        </Console>

        <Syslog name="SYS_LOG" host="test_server.com" port="514" 
                protocol="UDP" facility="LOCAL7">
        </Syslog>

        <RollingFile name="backupApp"
            fileName="C:/backup.log"
            filePattern="C:/backup-%d{yyyy-MM-dd_HH-mm}.log.gz">
            <PatternLayout>
                <Pattern>[%d{ISO8601}] [%c] - %p: %m%n</Pattern>
            </PatternLayout>
            <Policies>
                <TimeBasedTriggeringPolicy interval="1"
                    modulate="true" />
            </Policies>
        </RollingFile>

        <Failover name="FAILOVER" primary="SYS_LOG">
            <Failovers>
                <AppenderRef ref="backupApp"/>
            </Failovers>
        </Failover>     
    </Appenders>

    <Loggers>
        <Logger name="com.test.util.CustomLogger" level="info" additivity="false">
            <AppenderRef ref="SYS_LOG" />
            <AppenderRef ref="STDOUT" />
        </Logger>

        <Logger name="STDOUT" level="info" additivity="false">
            <AppenderRef ref="STDOUT" />
        </Logger>

        <Root level="info">
            <AppenderRef ref="STDOUT" />
            <AppenderRef ref="LOG" />
        </Root>

        <Root level="error">
            <AppenderRef ref="FAILOVER"/>
        </Root>
    </Loggers>
</Configuration>

感谢您的帮助.

推荐答案

调试过程中看到的是调用PluginBuilder#verifyNodeChildrenUsed()方法,您应该验证一下Node的子元素是否正确.如下所述,此方法名称与行为不符.

What I have seen while debugging is the PluginBuilder#verifyNodeChildrenUsed() method is called to, you would expect, verify that the child elements of the Node are correct. As I describe below, this method name does not match the behaviour.

对于故障转移附加程序,插件类型为:(顺便说一句,"isDeferChildren"处的额外"=="仅在toString()实现中,并且不影响测试.)

In the case of a Failover appender, the plugin type is: (btw, the extra "==" at "isDeferChildren" is just in the toString() implementation and does not affect the test.)

PluginType [pluginClass=class org.apache.logging.log4j.core.appender.FailoversPlugin, key=failovers, elementName=failovers, isObjectPrintable=false, isDeferChildren==false, category=core]

此方法的实现:

private void verifyNodeChildrenUsed() {
    final List<Node> children = node.getChildren();
    if (!(pluginType.isDeferChildren() || children.isEmpty())) {
        for (final Node child : children) {
            final String nodeType = node.getType().getElementName();
            final String start = nodeType.equals(node.getName()) ? node.getName() : nodeType + ' ' + node.getName();
            LOGGER.error("{} has no parameter that matches element {}", start, child.getName());
        }
   }
}

当nodeType是FailoversPlugin类(请参见上文)时,节点类型为"appender",但名称为"Failovers".因此,相等性测试将产生字符串"appender故障转移".

When the nodeType is the FailoversPlugin class (see above), the node type is "appender" but the name is "Failovers". So the test of equality produces the string "appender Failovers".

我尚未完全研究的是为什么调用此方法,以便如果节点不为空并且deferring属性为false,则必须显示错误消息.在我看来,这里的逻辑依赖于堆栈上的内容,因此进行跟踪很麻烦.

What I haven't dug into fully is WHY this method is called such that if the node is not empty and the property of deferring is false, the error message MUST be displayed. It seems to me that the logic here is dependent on something up-the-stack and tracing through this is cumbersome.

我真正想做的是问负责的开发者的意图是什么,因为我不清楚行为是否正确.好吧,在这种情况下显然是正确的. :S

What I'd really like to do is ask the developer responsible what's the intention, because it's not clear to me that the behaviour is correct. Well, obviously that's true in this case. :S

这篇关于Log4j2的FailoverAppender错误:追加程序故障转移没有与元素故障转移匹配的参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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