“log4j:configuration” 必须与 “(renderer....loggerFactory)?)”

2022-09-01 08:17:10

得到错误,当我将我的战争文件部署到tomcat时:

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

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

有什么建议吗?


答案 1

根据错误消息,DTD 期望所有元素都位于元素之前。你让他们走错了路。categoryroot


答案 2

请遵循以下顺序:

<renderer></renderer>

<appender></appender>

<plugin></plugin>

<logger></logger>

<category></category>

<root></root>

<loggerfactory></loggerfactory>

<categoryfactory></categoryfactory>

推荐