Java Logging与Log4J [英] Java Logging vs Log4J

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

问题描述

是否仍然需要将log4j库添加到Java 5项目中以便记录
让我们说一些具有一些不错的翻转设置的文件的例外情况。
或标准的util.logging工具也可以完成这项工作吗?

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?

你怎么看?

推荐答案

我会说你的util.logging可能对你描述的需求很好。

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

为了好决策树,请看 Log4j vs java.util.logging


问题一:
您是否预计需要Log4j具有JUL所没有的任何聪明的处理程序,例如SMTPHandler,NTEventLogHandler或者任何非常方便的FileHandler?

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?

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

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?

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

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?

如果您对以上任何一个问题的回答都是肯定的,请使用Log4j。如果你对所有人都回答肯定的问题,那么JUL就足够了,它已经方便地包含在SDK中了。

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.

那个说,现在几乎每个项目似乎都包括log4j,只是因为其他一些库使用它。

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

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

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