“log4j:configuration”必须匹配“(渲染器... .loggerFactory)?)”

时间:2012-09-07 16:23:19

标签: java tomcat maven log4j

在将war文件部署到tomcat时出错:

log4j:WARN The content of element type "log4j:configuration" must match "(renderer*,throwableRenderer?,appender*,plugin*,(category|logger)*,root?,(categoryFactory|loggerFactory)?)"

我google了一下,发现我的log4j.xml的排序可能是错误的,但它应该是正确的。

<?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 %d %c %x - %m%n"/>  
    </layout>  
  </appender>  

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

  <category name="org.springframework" additivity="false">  
    <priority value="info" />  
    <appender-ref ref="console" />  
  </category>  

</log4j:configuration>

有什么建议吗?

2 个答案:

答案 0 :(得分:57)

根据错误消息,DTD期望所有category元素都位于root元素之前。你有错误的方法。

答案 1 :(得分:0)

按照顺序-------------------->

`<renderer></renderer>

<appender></appender>

<plugin></plugin>

<logger></logger>

<category></category>

<root></root>

<loggerfactory></loggerfactory>

<categoryfactory></categoryfactory>`