使用log4j的优点和缺点
有人告诉我在我的日志项目中使用 log4j,但在使用 log4j 之前,我想知道它的缺点是什么,以便我可以找到一些解决方案来消除这些缺点。
I have been told to use log4j for my logging project,but before using log4j, i wanted to know what all are its disadvantages, so that i can find some solution to do away with those disadvantages.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果我今天要开始一个新项目,我会使用 SLF4J 进行日志记录。这是一个简单的 API,位于您的程序和您使用的日志库之间。您的程序将使用 SLF4J API,它将调用传递给您插入的实际日志记录库。您可以将不同的日志记录库与 SLF4J 一起使用(例如 Log4J 或 java.util 日志记录),并且可以切换到不同的日志记录库无需对您自己的源代码进行任何更改。
SLF4J API 有一个“本机”实现,称为 Logback。去年,我参与了一个项目,我们在项目后期决定从 Log4J 切换到 Logback,因为 Log4J 会锁定日志文件,而 Logback 不会(这意味着在 Windows 上,当 Log4J 打开日志文件时,您无法删除它) ; Logback 没有这个问题)。
If I would be starting a new project today I'd use SLF4J for the logging. This is a simple API which sits in between your program and the logging library that you use. Your program will use the SLF4J API, which passes the calls to the actual logging library that you plug in. You can use different logging libraries with SLF4J (for example Log4J or java.util logging), and you can switch to a different logging library without changing anything to your own source code.
There is a "native" implementation of the SLF4J API called Logback. Last year I was on a project in which we decided to switch from Log4J to Logback very late in the project, because Log4J locks logfiles and Logback does not (which means that on Windows, you can't delete a logfile while Log4J has it open; Logback doesn't have that problem).
我建议您阅读以下文章中有关 log4j 与 JUL 的内容 - http://java.sys-con。 com/node/48541。它对何时需要 log4j 以及它提供的好处进行了全面的讨论。
我假设您了解日志记录的优点。正如斯卡夫曼指出的,为了比较苹果和橙子——你需要了解你的橙子
I would recommend reading about log4j vs JUL in the following post - http://java.sys-con.com/node/48541. It offers a comprehensive discussion on when log4j is required and what benefits it offers.
I assume that you understand the advantages of logging. As skaffman pointed out in order to compare apple with oranges - you need to know about your oranges