log4j.properties和log4j.xml [英] log4j.properties vs log4j.xml

查看:382
本文介绍了log4j.properties和log4j.xml的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我被要求从属性样式配置转换为xml样式.该过程本身很简单,不会给我带来任何麻烦,我只是很好奇为什么我被问到这个,然后寻找原因.我发现这篇不错的帖子为什么选择XML而不是属性文件进行Log4J配置?(超过3岁,但仍然是我能找到的最有用的信息),它指向的是

I was asked to move from properties style configuration to xml style. The process itself is straightforward and it is not causing me any trouble, I was simply curious why I got asked this and I looked for the reason. I found this nice post Why chose XML over properties files for Log4J configuration? (more than 3 years old but still the most informative I could find), which was pointing pointing to this even older tutorial. They state

属性可以通过属性文件或XML文件定义.

Properties can be defined by a properties file or by an XML file.

Log4j查找一个名为log4j.xml的文件,然后查找一个名为log4j.properties的文件.两者都必须放在src文件夹中.

Log4j looks for a file named log4j.xml and then for a file named log4j.properties. Both must be placed in the src folder.

我检查了一下,与该语句相反,发现Log4j首先查找属性文件,然后第二次查找xml.实际上,如果我将两者都放在同一个文件夹中,则输出将根据属性文件进行格式化.那么,我是否误解了该声明?这是完全错误的吗?我在log4j 1.2.17 上针对log4j 1.2.14 发表了声明,log4j团队是否可以更改优先级?我找不到任何相关文档,但这将是一个奇怪的趋势反转,因为xml似乎是配置log4j的首选方式

I checked it out and, contrary to the statement, found out that Log4j looks first for the properties file and in a second time for xml. In fact, if I keep both in the same folder, the output is formatted according to the properties file. So, am I misunderstood the statement? Is it simply wrong? The statement has been made for log4j 1.2.14 while I am on log4j 1.2.17, is it possible the log4j team changed the priority? I couldn't find any related documentation, but it will be a strange trend inversion since the xml looked to be the preferred way to configure log4j

推荐答案

看看JavaDoc. PropertyConfiguratorClass (log4j.properties)的文档指出

Have a look at the JavaDoc. The documentation of the PropertyConfiguratorClass (log4j.properties) points out that

PropertyConfigurator无法处理高级配置 DOMConfigurator支持的功能,例如自定义支持 错误处理程序,嵌套的附加程序,例如AsyncAppender等.

The PropertyConfigurator does not handle the advanced configuration features supported by the DOMConfigurator such as support custom ErrorHandlers, nested appenders such as the AsyncAppender, etc.

因此 DOMConfigurator (log4j.xml)提供高级选项.

So the DOMConfigurator (log4j.xml) offers advanced options.

此外,您可以使用提供的log4j.dtd .

Beside that you can have (at least a simple) validity check of log4j.xml files using the provided log4j.dtd.

如果您不使用高级功能,则无需从属性更改为xml文件.

If youd do not make use of the advanced features it is needless to change from properties to xml files.

您真正应该考虑的是将log4j更改为 log4j 2 beta 甚至 slf4j . log4j的开发已停止,其创始人(@Ceki)发明了slf4j.

What you really should think about is to change from log4j to log4j 2 beta or even slf4j. Development of log4j has stopped and the founder of it (@Ceki) invented slf4j.

这篇关于log4j.properties和log4j.xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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