为什么选择XML作为Log4J配置的属性文件? [英] Why chose XML over properties files for Log4J configuration?

查看:113
本文介绍了为什么选择XML作为Log4J配置的属性文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何理由在Log4J配置的属性文件上使用XML?

Are there any reasons to use XML over properties files for Log4J configuration?

推荐答案

有一个关于这两篇博客的优点。以下部分是该博客的引用:

There's an interesting discussion on the merits of both in this blog. The section below is a quote from that blog:


属性可以由属性文件或XML文件定义。 Log4j查找名为log4j.xml的文件,然后查找名为log4j.properties的文件。 两者都必须放在src文件夹中

属性文件比XML文件简洁。 XML要求log4j.dtd也放在源文件夹中。 XML需要dom4j.jar,它可能不包含在较旧的Java版本中。

The property file is less verbose than an XML file. The XML requires the log4j.dtd to be placed in the source folder as well. The XML requires a dom4j.jar which might not be included in older Java versions.

属性文件不支持某些高级配置选项,如Filters,自定义ErrorHandler和一个特殊的appender的类型,即AsyncAppender。 ErrorHandlers定义了如何处理log4j本身的错误,例如配置错误的appender。过滤器更有趣。从可用的过滤器中,我认为属性文件中实际上缺少级别范围过滤器。

The properties file does not support some advanced configuration options like Filters, custom ErrorHandlers and a special type of appenders, i.e. AsyncAppender. ErrorHandlers defines how errors in log4j itself are handled, for example badly configured appenders. Filters are more interesting. From the available filters, I think that the level range filter is really missing for property files.

此过滤器允许定义[n] appender应接收来自的日志消息等级INFO到WARN。这允许跨不同的日志文件分割日志消息。一个用于DEBUGGING消息,另一个用于警告,...

This filter allows to define that a[n] appender should receive log messages from Level INFO to WARN. This allows to split log messages across different logfiles. One for DEBUGGING messages, another for warnings, ...

属性appender仅支持最低级别。如果你设置了INFO,你也会收到WARN,ERROR和FATAL消息。

The property appender only supports a minimum level. If you set it do INFO, you will receive WARN, ERROR and FATAL messages as well.






解决我原来答案的评论:斜体是我的重点。出于本教程的目的,作者选择掩盖或无意中省略了属性或xml只需要在类路径上,而不是需要在src文件夹中。将它们添加到类路径的一种简单方法是将它们添加到src文件夹中,因此为了本教程的目的显然已经足够了。


To address the comments on my original answer: The italics are my emphasis. For the purposes of the tutorial the author has chosen to gloss over, or unintentionally omitted that the properties or xml need only be on the classpath rather than needing to be in the src folder. A simple way to add them to the classpath is to add them to the src folder, so for the purpose of the tutorial that was obviously deemed sufficient.

这些都不是与问题或答案意图直接相关,即讨论使用xml文件配置log4j的优点或其他方面。我认为报价的其余部分对于那些希望做出明智选择的人来说是相关且有用的。

None of this is directly relevant to the question asked or the intention of the answer, which is to discuss the merits or otherwise of using xml files to configure log4j. I consider that the rest of the quote is relevant and useful to those looking to make an informed choice.

这篇关于为什么选择XML作为Log4J配置的属性文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆