Log4j DailyRollingFileAppender 与 ConsoleAppender 性能对比

发布于 2024-10-05 00:08:10 字数 589 浏览 0 评论 0原文

我们使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无所谓啦 2024-10-12 00:08:10

您的论点是正确的,逻辑表明存在开销/性能影响。多少?如果您担心性能受到影响,则应该自行测量。

这实际上取决于您有多少日志记录语句。许多调试语句是最糟糕的,因为它们会影响性能,除非您使用 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文