log4cxx 配置文件语法
我刚刚发现 log4cxx 日志框架。 似乎有两种不同的语法用于编写配置文件:
xml 方式
键值方式
这两种方法是否有区别或最佳实践?
I'm just discovering log4cxx logging framework.
It seems there are two different syntaxes for writing config file:
xml manner
key-value manner
Is there a difference or a best practice in this two approaches?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 log4j 中,Ceki Gulcu(作者)建议 XML 配置优先于文本文件,并且它在默认初始化中也优先(
log4j.xml
优先于log4j.txt
)。使用 XML 配置可以比使用文本文件实现更多功能(我认为您无法使用文本文件配置操作记录器可加性并设置 log4j 调试模式)。也就是说,log4cxx 首先也会查找
log4cxx.xml
,但网上几乎没有任何配置示例(也没有官方文档),因此您可能需要分析 < code>DOMConfigurator 源代码来找出可能的情况(参考 log4j 示例可能会产生误导,因为它并不总是完全相同)。总而言之,log4cxx 在 C++ 世界中的受欢迎程度甚至无法与 log4j 在 Java 中的受欢迎程度相提并论。我想知道为什么(除了大量的临时解决方案之外,那里到底流行什么)。
In log4j, Ceki Gulcu (the author) suggests XML configuration over text file, and it takes precedence in default initialization, too (
log4j.xml
overlog4j.txt
). You can achieve slightly more with XML configuration than with the text file (I think you cannot manipulate logger additivity and set log4j debug mode with text file configuration).That said, log4cxx first looks for
log4cxx.xml
, too, but there are hardly any examples of configuration on the net (and no official documentation, either), so you'll probably need to analyse theDOMConfigurator
source code to find out what's possible (referring to log4j examples may prove misleading, as it's not always exactly the same thing).To conclude, log4cxx popularity in C++ world does not even come close to log4j's in Java. I wonder why (and what the heck IS popular there, except for tons of ad-hoc solutions).
这实际上并不是问题的答案,但是当你用谷歌搜索时:
这个问题是最热门的搜索结果。正如 @MaDa 提到的,很难找到 log4cxx 和语法描述的 XML 配置文件示例。所以就是这样。最简单的方法是登录控制台并登录日志文件。
和简单的用法示例:
This isn't actually an answer for the question but when you google for:
this question is the top search result. As it was mentioned by @MaDa it's difficult to find an XML config file example for log4cxx and syntax description. So this is it. Simplest possible, just to log into console and into a log file.
And simple usage example: