Java 日志记录与 Log4J

标签 java logging log4j java.util.logging

<分区>

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

你怎么看?

最佳答案

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

要获得好的决策树,请查看 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.

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

关于Java 日志记录与 Log4J,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23229763/

相关文章:

java - NoSuchMethodError : org. slf4j.impl.StaticLoggerBinder.getSingleton()

带有 ProJavaFX 2 的 JavaFX,带下划线的导入

Android Log.X 不打印堆栈跟踪

Java For() 循环初始值错误,最终停止点错误

logging - 拦截来自 Ant 的 Commons 日志记录

c++ - Poco Logger 更改 Message 参数

java - 在 Spring 中启用日志记录

java - 我在哪里可以在 JUnit 测试类中配置 log4j?

java - 关于Java定位

java - 将 double 分组到映射以创建直方图