log4j:WARN Document root element "log4j:configuration", must match DOCTYPE root "null"

dmgmyza picture dmgmyza · Jun 21, 2012 · Viewed 38k times · Source

I want to connect my log4j.xml with log4j.xsd (xml schema). Project don't have any warnings or errors. But when I start it, Ihave such console warnings:

log4j:WARN Continuable parsing error 6 and column 66.

log4j:WARN Document root element "log4j:configuration", must match DOCTYPE root "null".

log4j:WARN Continuable parsing error 6 and column 66.

log4j:WARN Document is invalid: no grammar found.

I think, problem in schema Location. But I don't know, how to write it normally. Hope for your's advices.

My 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>

And my 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>

P.S. Sorry for my english...

Answer

Gernot picture Gernot · Feb 25, 2013

Add the following line to your log4j.xml config file right after the <xml> element:

<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

Complete log4j Configuration Example from their wiki:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
  <appender name="console" class="org.apache.log4j.ConsoleAppender"> 
    <param name="Target" value="System.out"/> 
    <layout class="org.apache.log4j.PatternLayout"> 
      <param name="ConversionPattern" value="%-5p %c{1} - %m%n"/> 
    </layout> 
  </appender> 

  <root> 
    <priority value ="debug" /> 
    <appender-ref ref="console" /> 
  </root>

</log4j:configuration>