java “log4j:configuration”必须匹配“(renderer....loggerFactory)?)”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12321943/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 08:26:06  来源:igfitidea点击:

“log4j:configuration” must match “(renderer….loggerFactory)?)”

javatomcatmavenlog4j

提问by Jaanus

getting error, when deploying my war file to tomcat:

将我的War文件部署到 tomcat 时出现错误:

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

I googled around and found out that ordering of my log4j.xml could be wrong, but it should be correct.

我搜索了一下,发现我的 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>

Any suggestions?

有什么建议?

回答by Ian Roberts

According to the error message, the DTD expects all categoryelements to be ahead of the rootelement. You have them the wrong way round.

根据错误消息,DTD 期望所有category元素都在root元素之前。你把它们弄错了。

回答by Aioria de Leo

Follow this order:

按照这个顺序:

<renderer></renderer>

<appender></appender>

<plugin></plugin>

<logger></logger>

<category></category>

<root></root>

<loggerfactory></loggerfactory>

<categoryfactory></categoryfactory>