Java 日志与 Log4J [英] Java Logging vs Log4J

查看:34
本文介绍了Java 日志与 Log4J的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否仍然值得将 log4j 库添加到 Java 5 项目中只是为了记录让我们说一些具有一些不错的翻转设置的文件的例外情况.还是标准的 util.logging 工具也能完成这项工作?

你怎么看?

解决方案

我想说你可能对 util.logging 满足你描述的需求没问题.

对于一个好的决策树,看看 Log4j vs java.util.logging

<块引用>

问题一:您是否预计需要 Log4j 拥有而 JUL 没有的任何智能处理程序,例如 SMTPHandler、NTEventLogHandler 或任何非常方便的 FileHandlers?

<块引用>

问题二:您是否看到自己想要频繁地切换日志输出的格式?您是否需要一种简单、灵活的方法来做到这一点?换句话说,你需要Log4j的PatternLayout吗?

<块引用>

问题三:在生产环境中编译和部署应用程序之后,您是否预计确实需要能够更改应用程序中复杂的日志配置?您的配置听起来是否类似于来自此类的严重消息通过电子邮件发送给支持人员?来自类子集的严重消息被记录到我们服务器上的系统日志守护程序中;来自另一个类子集的警告消息被记录到网络驱动器 A 上的文件中;然后来自任何地方的所有消息都被记录到网络驱动器 B 上的一个文件中"?你是否看到自己每隔几天就调整一次?

<块引用>

如果您对上述任何问题的回答是肯定的,请使用 Log4j.如果您对所有这些都回答肯定的否",则 JUL 将绰绰有余,并且它已方便地包含在 SDK 中.

也就是说,现在几乎每个项目似乎都包含 log4j,只是因为其他库使用了它.

Is it still worth to add the log4j library to a Java 5 project just to log let's say some exceptions to a file with some nice rollover settings. Or will the standard util.logging facility do the job as well?

What do you think?

解决方案

I'd say you're probably fine with util.logging for the needs you describe.

For a good decision tree, have a look at Log4j vs java.util.logging

Question One : Do you anticipate a need for any of the clever handlers that Log4j has that JUL does not have, such as the SMTPHandler, NTEventLogHandler, or any of the very convenient FileHandlers?

Question Two : Do you see yourself wanting to frequently switch the format of your logging output? Will you need an easy, flexible way to do so? In other words, do you need Log4j's PatternLayout?

Question Three : Do you anticipate a definite need for the ability to change complex logging configurations in your applications, after they are compiled and deployed in a production environment? Does your configuration sound something like, "Severe messages from this class get sent via e-mail to the support guy; severe messages from a subset of classes get logged to a syslog deamon on our server; warning messages from another subset of classes get logged to a file on network drive A; and then all messages from everywhere get logged to a file on network drive B"? And do you see yourself tweaking it every couple of days?

If you can answer yes to any of the above questions, go with Log4j. If you answer a definite no to all of them, JUL will be more than adequate and it's conveniently already included in the SDK.

That said, pretty much every project these days seems to wind up including log4j, if only because some other library uses it.

这篇关于Java 日志与 Log4J的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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