我无法让我的log4j2.xml文件符合架构。没有模式规范,我没有任何错误,但是有了它,我得到了:
cvc-complex-type.2.4.d: Invalid content was found starting with element 'File'. No child element is expected at
this point.
cvc-complex-type.2.4.d: Invalid content was found starting with element 'Logger'. No child element is expected
at this point.
在没有模式的情况下,日志记录可以正常工作,但是Eclipse警告其丢失,因此我希望将其安装到位。这是我正在使用的log4j2.xml文件:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration strict="true"
xmlns="http://logging.apache.org/log4j/2.0/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config
https://raw.githubusercontent.com/apache/logging-log4j2/log4j-2.11.1/log4j-core/src/main/resources/Log4j-config.xsd">
<Appenders>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5p %-5level - %msg%n"/>
</Console>
<File name="file" fileName="mylogfile.log" append="true">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5p %-5level - %msg%n"/>
</File >
</Appenders>
<Loggers>
<Root level="DEBUG">
<AppenderRef ref="console"/>
<AppenderRef ref="file"/>
</Root>
<Logger name="org.apache.http" level="WARN" additivity="false">
<AppenderRef ref="console"/>
<AppenderRef ref="file"/>
</Logger>
<Logger name="net.authorize.util" level="WARN" additivity="false">
<AppenderRef ref="console"/>
<AppenderRef ref="file"/>
</Logger>
<Logger name="net.authorize.api" level="WARN" additivity="false">
<AppenderRef ref="console"/>
<AppenderRef ref="file"/>
</Logger>
</Loggers>
</Configuration>
答案 0 :(得分:1)
这是因为定义为here
的架构没有定义称为文件的Appender,您是否打算在Appender节点下使用Layout?尽管很奇怪,但他们的示例here显示了在Console节点之后使用它们的情况。
定义根节点出现在所有Logger节点之后
将验证的样本文件
<?xml version="1.0" encoding="UTF-8"?>
<Configuration strict="true"
xmlns="http://logging.apache.org/log4j/2.0/config"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://logging.apache.org/log4j/2.0/config
https://raw.githubusercontent.com/apache/logging-log4j2/log4j-2.11.1/log4j-core/src/main/resources/Log4j-config.xsd">
<Appenders>
<Appender type="file" name="" fileName="mylogfile.log">
<Layout type="">
<Pattern>%d{yyyy-MM-dd HH:mm:ss z} %-5p %-5level - %msg%n</Pattern>
</Layout>
</Appender>
<Console name="console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{yyyy-MM-dd HH:mm:ss z} %-5p %-5level - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="org.apache.http" level="WARN" additivity="false">
<AppenderRef ref="console"/>
<AppenderRef ref="file"/>
</Logger>
<Logger name="net.authorize.util" level="WARN" additivity="false">
<AppenderRef ref="console"/>
<AppenderRef ref="file"/>
</Logger>
<Logger name="net.authorize.api" level="WARN" additivity="false">
<AppenderRef ref="console"/>
<AppenderRef ref="file"/>
</Logger>
<Root level="DEBUG">
<AppenderRef ref="console"/>
<AppenderRef ref="file"/>
</Root>
</Loggers>
</Configuration>