Log4j 2.0 和 SLF4J 以及 Java 日志框架的永无止境的未来
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12094564/
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 2.0 and SLF4J and the never ending future of java logging frameworks
提问by Adam Gent
So I just found out today that Log4J 2.0 is now actively being developed, there is an alpha version and it is said to replace logback.
所以我今天才发现 Log4J 2.0 现在正在积极开发中,有一个 alpha 版本,据说它会取代 logback。
Right now in my app I have close to 4 maybe more logging frameworks:
现在在我的应用程序中,我有接近 4 个可能更多的日志记录框架:
- Java Util Logging
- log4j
- slf4j
- logback (ignored thanks to a maven provided hack)
- commons logging (ignored thanks to a maven provided hack)
- And tomcat has its own JULI adapter
- Java 实用程序日志记录
- 日志4j
- slf4j
- logback(由于 maven 提供的 hack 被忽略)
- 公共日志记录(由于 maven 提供的 hack 被忽略)
- 并且 tomcat 有自己的 JULI 适配器
I have been using log4j (1.2.x) because frankly I just haven't needed the featuresof the newer guys but I have been tempted lately to switch to SLF4J and mainly because I don't want to have rewrite my complicated log4j configurations files to a new format(logback).
我一直在使用 log4j (1.2.x) 因为坦率地说我只是不需要新人的功能但我最近很想切换到 SLF4J 主要是因为我不想重写我复杂的 log4j 配置文件到新格式(logback)。
Now my question is in terms of what I should code against is SLF4J the right choice for the future given log4j 2.0.
现在我的问题是关于我应该编码的内容是 SLF4J 是未来给定 log4j 2.0 的正确选择。
It seems like I should just stick with old log4j (1.2.x
) as it is the lowest common denominator?
似乎我应该坚持使用旧的 log4j ( 1.2.x
) 因为它是最小的公分母?
UPDATE:on further examination of log4j 2.0 while very similar it appears the configuration is not backward compatible with log4j 1.2. Looks like logback is the best choice.
更新:进一步检查 log4j 2.0 虽然非常相似,但似乎配置与 log4j 1.2 不向后兼容。看起来 logback 是最好的选择。
采纳答案by slim
It's a subjective question.
这是一个主观的问题。
I'd suggest using slf4j, since it can use log4j as a backend if that's what you need.
我建议使用 slf4j,因为如果您需要,它可以使用 log4j 作为后端。
You're likely to be using a number of components which may all use different logging APIs. It's good to be able to consolidate the output via those APIs into a single output route.
您可能会使用许多组件,这些组件可能都使用不同的日志记录 API。能够通过这些 API 将输出合并到单个输出路径中是件好事。
回答by Ceki
Disclaimer: I am the founder of log4j, slf4j and logback projects but unaffiliated with log4j 2.0.
免责声明:我是 log4j、slf4j 和 logback 项目的创始人,但与 log4j 2.0 无关。
As I understand it, notwithstanding its name, log4j 2.0 is very different than log4j 1.x. As far as the user API is concerned, log4j 2.0 is largely incompatible with log4j 1.x. Log4j 2.0 provides an adaptation layer for log4j 1.x which at present time (2012-08) is undocumented
.
据我了解,尽管名称如此,但 log4j 2.0 与 log4j 1.x 非常不同。就用户 API 而言,log4j 2.0 在很大程度上与 log4j 1.x 不兼容。Log4j 2.0 为 log4j 1.x 提供了一个适配层,目前 (2012-08) 是undocumented
.