我想将我的 log4j.xml 与 log4j.xsd(xml 模式)连接起来。项目没有任何警告或错误。但是当我启动它时,我有这样的控制台警告:
log4j:WARN 可继续解析错误 6 和第 66 列。
log4j:WARN 文档根元素“log4j:configuration”,必须匹配 DOCTYPE 根“null”。
log4j:WARN 可继续解析错误 6 和第 66 列。
log4j:WARN 文档无效:未找到语法。
我认为,模式位置存在问题。但我不知道,如何正常写。希望得到您的建议。
我的 log4j.xml:
<?xml version="1.0" encoding="UTF-8" ?>
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
debug="false"
xsi:schemaLocation="http://www.example.org/log4j log4j.xsd ">
<appender name="logFileAppender" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="E:/Codes/HorseRacing/logFile.log"/>
<param name="MaxFileSize" value="1MB"/>
<param name="MaxBackupIndex" value="5"/>
<param name="Encoding" value="UTF-8"/>
<layout class="org.apache.log4j.EnhancedPatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} [%-5p][%-16.16t][%40.40c] - %m%n"/>
</layout>
</appender>
<appender name="ConsoleAppender" class="org.apache.log4j.ConsoleAppender">
<param name="Encoding" value="Cp866"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{ISO8601} [%-5p][%-25.25l][%10.10c] - %m%n" />
</layout>
</appender>
<logger name="appLogger">
<level value="INFO"/>
<appender-ref ref="logFileAppender"/>
<appender-ref ref="ConsoleAppender"/>
</logger>
</log4j:configuration>
还有我的 log4j.xsd:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema attributeFormDefault="unqualified"
elementFormDefault="qualified" version="1.0"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:element name="configuration">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="appender">
<xsd:complexType>
<xsd:sequence>
<xsd:element maxOccurs="unbounded" name="param">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="value" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="layout">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="param">
<xsd:complexType>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="value" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="class" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
<xsd:attribute name="class" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="logger">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="level">
<xsd:complexType>
<xsd:attribute name="value" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element maxOccurs="unbounded" name="appender-ref">
<xsd:complexType>
<xsd:attribute name="ref" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:sequence>
<xsd:attribute name="debug" type="xsd:boolean" />
<xsd:attribute name="schemaLocation" type="xsd:string" />
</xsd:complexType>
</xsd:element>
</xsd:schema>
<logger name="appLogger">
<level value="INFO"/>
<appender-ref ref="logFileAppender"/>
<appender-ref ref="ConsoleAppender"/>
</logger>
</log4j:configuration>
PS对不起我的英语...