Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 926
dmgmyza Avatar asked Jun 21 '12 20:06

dmgmyza


People also ask

Where is log4j configuration file?

The file is named log4j. properties and is located in the $DGRAPH_HOME/dgraph-hdfs-agent/lib directory. The file defines the ROLLINGFILE appenders for the root logger and also sets the log level for the file.

What is root level in log4j2?

Configuration: the root element of a log4j2 configuration file; the status attribute represents the level at which internal log4j events should be logged. Appenders: this element contains a list of appenders; in our example, an appender corresponding to the System console is defined.


2 Answers

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>
like image 93
Gernot Avatar answered Sep 21 '22 19:09

Gernot


The jar that is producing this message expects to see a DTD validated, not schema validated configuration.

Check your classpath. You are using a too old version of the framework for this configuration. Very likely you have multiple versions of a jar with the same name on your disk, and such occurences will point you to the problem and to removal of very old libraries that you do not really want to use.

like image 22
Jirka Hanika Avatar answered Sep 22 '22 19:09

Jirka Hanika