如何解决log4j中的警告??? Continuable parsing error ...元素类型“log4j:configuration”的内容必须匹配

时间:2014-09-05 11:47:23

标签: java log4j appender log4

显示警告......

log4j:WARN Continuable parsing error 28 and column 23
log4j:WARN The content of element type "log4j:configuration" must match
  "(renderer*,appender*,(category|logger)*,root?,categoryFactory?)".

执行java文件时

    <?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    <log4j:configuration>
        <appender name="console" class="org.apache.log4j.ConsoleAppender">
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="\n[%-6r] - %m" />
            </layout>
        </appender>
        <category name="se.jayway.ddsteps">
            <priority value="info"></priority>
        </category>
        <appender name="FILE" class="org.apache.log4j.FileAppender">
            <param name="file"
                value="D:/workspace_Testing/IdMUnitTests/logs/IdMUnitlog.log" />
            <param name="immediateFlush" value="true" />
            <param name="threshold" value="debug" />
            <param name="append" value="false" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%m%n" />
            </layout>
        </appender>

        <root>
            <priority value="INFO"></priority>
            <appender-ref ref="console" />
            <appender-ref ref="FILE" />
        </root>
    </log4j:configuration>

1 个答案:

答案 0 :(得分:36)

根据错误消息,DTD期望指定订单中的所有元素。

(renderer*,appender*,(category|logger)*,root?,categoryFactory?)


<?xml version="1.0" encoding="UTF-8" ?>
    <!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
    <log4j:configuration>
        <appender name="console" class="org.apache.log4j.ConsoleAppender">
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="\n[%-6r] - %m" />
            </layout>
        </appender>

        <appender name="FILE" class="org.apache.log4j.FileAppender">
            <param name="file"
                value="D:/workspace_Testing/IdMUnitTests/logs/IdMUnitlog.log" />
            <param name="immediateFlush" value="true" />
            <param name="threshold" value="debug" />
            <param name="append" value="false" />
            <layout class="org.apache.log4j.PatternLayout">
                <param name="ConversionPattern" value="%m%n" />
            </layout>
        </appender>

        <category name="se.jayway.ddsteps">
            <priority value="info"></priority>
        </category>

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

    </log4j:configuration>

XML配置订单

所以请记住按顺序编写xml

<renderer></renderer>

<appender></appender>

<plugin></plugin>

<logger></logger>

<category></category>

<root></root>

<loggerfactory></loggerfactory>

<categoryfactory></categoryfactory>