log4j2-error appenders包含无效的元素或属性“flume”

7fhtutme  于 2021-06-04  发布在  Flume
关注(0)|答案(2)|浏览(699)

我正在尝试使用log4j2的flume appender属性。但是在运行程序时出现以下错误。

2016-01-20 16:36:42,436 main ERROR Appenders contains an invalid element or attribute "Flume"
    2016-01-20 16:36:42,436 main ERROR Appenders contains an invalid element or attribute "Flume"
    2016-01-20 16:36:42,446 main ERROR Unable to locate appender "eventLogger" for logger config "root"
    2016-01-20 16:36:42,446 main ERROR Unable to locate appender "eventLogger" for logger config "root"

log4j.xml文件是:

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
        <PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n" />
    </Console>
    <Flume name="eventLogger" compress="false" type="Avro">
        <Agent host="192.168.8.50" port="41414"/>
    </Flume>
  </Appenders>
  <Loggers>
    <Root level="info">
        <AppenderRef ref="Console" />
        <AppenderRef ref="eventLogger" />
    </Root>
  </Loggers>
</Configuration>

在java代码中

LoggerContext context = (org.apache.logging.log4j.core.LoggerContext) LogManager.getContext(false);
File file = new File("src/log4j2.xml");
context.setConfigLocation(file.toURI());

我怎样才能找出问题。可能是log4j2工作不正常。

rfbsl7qr

rfbsl7qr1#

你的类路径中有log4j flume jar吗?如果您将status设置为debug,您应该会看到更多信息。

ffscu2ro

ffscu2ro2#

我遇到了类似的情况,即使appender元素在appenders下也无法识别。解决方法是在配置中添加strict=“true”,如下所示
配置状态=“warn”strict=“true”

相关问题