How to solve the warnings in log4j???Continuable parsing error…The content of element type “log4j:configuration” must match

我们两清 提交于 2019-12-30 08:06:10

问题


Warnings are shown ...

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?)".

when execute the java files

    <?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:


According to the error message, the DTD expects all elements in an order specified.

(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 Configuration Order

So remember to write xml in that order

<renderer></renderer>

<appender></appender>

<plugin></plugin>

<logger></logger>

<category></category>

<root></root>

<loggerfactory></loggerfactory>

<categoryfactory></categoryfactory>


来源:https://stackoverflow.com/questions/25685217/how-to-solve-the-warnings-in-log4jcontinuable-parsing-error-the-content-of

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!