我正在尝试使用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无法正常工作。
答案 0 :(得分:1)
你的classpath中有log4j水槽吗?如果将状态设置为debug,则应该看到更多信息。
答案 1 :(得分:0)
我遇到了类似的情况,即使在Appenders中也无法识别Appender元素。解决方法是在配置中添加strict =“ true”,如下所示
配置状态=“ WARN”严格=“ true”