Log4j DailyRollingFileAppender 与 ConsoleAppender 性能对比
我们使用 Log4j v1.2.14。我们已经在使用 org. apache.log4j.ConsoleAppender,现在我们有一个要求/需要有每日轮换日志。因此,我们计划使用 org.apache.log4j.DailyRollingFileAppender 拥有每日轮换日志。
我的问题是,DailyRollingFileAppender 是否会比 ConsoleAppender 产生额外的开销/对性能产生影响,因为它必须另外检查文件是否必须在每个打印语句中旋转/翻转?
任何意见/用户体验也将受到赞赏。
We're using Log4j v1.2.14. We're already using org.apache.log4j.ConsoleAppender and now we've a requirement/need to have daily rotating logs in place. Hence, we're planning to use org.apache.log4j.DailyRollingFileAppender to have daily rotating logs.
My question is, is DailyRollingFileAppender an additional overhead/have performance impact over ConsoleAppender, because it has to additionally check for whether the file has to be rotated/rollover in each print statement?
Any opinions/user experience are also appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的论点是正确的,逻辑表明存在开销/性能影响。多少?如果您担心性能受到影响,则应该自行测量。
这实际上取决于您有多少日志记录语句。许多调试语句是最糟糕的,因为它们会影响性能,除非您使用
logger.isDebugEnabled()
类型的防护。如果您负担得起,我建议使用 Logback 作为底层实现。 Logback 的主要关注点是速度,它似乎竭尽全力确保它比其他日志系统更快。
Your arguments are correct and logic dictates that an overhead/performance impact exists. How much? You should measure it by yourself if you're afraid of the performance hit.
It really depends on how many logging statements you have. Lots of debugging statements are the worst because they can impact performance, unless you are using guards of type
logger.isDebugEnabled()
.If you can afford it, I'd suggest switching to slf4j with Logback as underlying implementation. Logback's main focus is speed and it seems to go to great lengths to make sure it's faster than other logging systems.