gpt4 book ai didi

java - 为什么选择 XML 而不是 Log4J 配置的属性文件?

转载 作者:IT老高 更新时间:2023-10-28 20:44:13 28 4
gpt4 key购买 nike

是否有任何理由在 Log4J 配置中使用 XML 而不是属性文件?

最佳答案

merits of both in this blog 上有一个有趣的讨论。 .以下部分是该博客的引述:

Properties can be defined by a properties file or by an XML file. Log4j looks for a file named log4j.xml and then for a file named log4j.properties. Both must be placed in the src folder.

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.

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.

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, ...

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 文件夹,因此对于本教程的目的而言,这显然已经足够了。

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

关于java - 为什么选择 XML 而不是 Log4J 配置的属性文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1256835/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com