java 使用 log4j.xml 时的 log4j 警告消息
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3097582/
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
log4j warning message while using log4j.xml
提问by fei
i'm trying to convert my log4j.properties into log4j.xml because i need to use some of the filter feature. i'm getting a bunch of warning when i start the application, i'm not exactly sure how to solve them:
我正在尝试将我的 log4j.properties 转换为 log4j.xml,因为我需要使用一些过滤器功能。当我启动应用程序时收到一堆警告,我不确定如何解决它们:
log4j:WARN Continuable parsing error 4 and column 69
log4j:WARN Attribute "threshold" for element type "log4j:configuration" has a default value and must be specified in a standalone document.
log4j:WARN Continuable parsing error 4 and column 69
log4j:WARN Attribute "debug" for element type "log4j:configuration" has a default value and must be specified in a standalone document.
log4j:WARN Continuable parsing error 4 and column 69
log4j:WARN Attribute "reset" for element type "log4j:configuration" has a default value and must be specified in a standalone document.
log4j:WARN Continuable parsing error 20 and column 23
log4j:WARN The content of element type "log4j:configuration" must match "(renderer*,appender*,plugin*,(category|logger)*,root?,(categoryFactory|loggerFactory)?)".
log4j:WARN Unrecognized element param
i'm just trying with a very simple log4j.xml file as well:
我也只是尝试使用一个非常简单的 log4j.xml 文件:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
<appender name="A1" class="org.apache.log4j.ConsoleAppender">
<param name="Threshold" value="INFO"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%-5p | %d{MM-dd-yyyy HH:mm:ss.SSS} | %t | %c(%L) - %m%n"/>
</layout>
</appender>
<root>
<priority value="INFO"/>
<appender-ref ref="A1"/>
</root>
</log4j:configuration>
is there anything i missed here? thanks!
有什么我在这里错过的吗?谢谢!
采纳答案by erickson
The standalone attribute, roughly speaking, declares that the information set is not affected by any content outside the document. However, in this case, it isn't true, because the attributes have default values that are specified in the external DTD.
粗略地说,standalone 属性声明了信息集不受文档外任何内容的影响。但是,在这种情况下,情况并非如此,因为属性具有在外部 DTD 中指定的默认值。
回答by Sean Reilly
As you suspect, removing the standalone="yes" attribute from the xml declaration will solve the problem. Standalone="yes" does some subtle things (here's the official spec). In this case the declaration is affecting how the validating xml parser used by log4j parses an xml document that refers to a dtd.
如您所料,从 xml 声明中删除 standalone="yes" 属性将解决问题。Standalone="yes" 做了一些微妙的事情(这里是官方规范)。在这种情况下,声明会影响 log4j 使用的验证 xml 解析器如何解析引用 dtd 的 xml 文档。
Removing that attribute from the declaration is probably correct, and should not meaningfully affect your log4j configuration.
从声明中删除该属性可能是正确的,并且不会对您的 log4j 配置产生有意义的影响。

