附加器/ console.xml
<?xml version="1.0" encoding="UTF-8" ?>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} log4j2-dev %5p %c{1}:%L - %m%n"/>
</Console>
log4j2.dev.xml
<?xml version="1.0" encoding="UTF-8" ?>
<Configuration xmlns:xi="http://www.w3.org/2001/XInclude">
<Appenders>
<xi:include href="appender/console.xml" />
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</Configuration>
我编写了一个使用xmlns:xi
的简单log4j2配置(上图)。错误输出是
ERROR StatusLogger No log4j2 configuration file found. Using default configuration: logging only errors to the console.
2015-11-14 16:19:34,348 ERROR Appenders contains an invalid element or attribute "xi:include"
2015-11-14 16:19:34,376 ERROR Unable to locate appender Console for logger
但是,如果我合并appender/console.xml
和log4j2.dev.xml
并使用合并后的<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss} log4j2-dev %5p %c{1}:%L - %m%n"/>
</Console>
</Appenders>
<Loggers>
<Root level="INFO">
<AppenderRef ref="Console"/>
</Root>
</Loggers>
</configuration>
。错误消失了。
{{1}}
我google了很多。但找不到解决方案来解决它。请帮忙。