从 log4j 输出通过电子邮件发送日志条目的机制

发布于 2024-10-05 18:22:13 字数 212 浏览 0 评论 0原文

log4j 的 SMTPAppender 未通过电子邮件发送 INFO 日志条目时遇到了一些问题,我想我已经解决了这个问题。但现在我很好奇这是否是最好的解决方案。我经常根据不同日志文件的输出发送电子邮件。有没有比 SMTPAppender 更好的电子邮件解决方案?我不想损害我的应用程序的性能,并且电子邮件发送是异步发生的。如果能每 5 分钟通过电子邮件发送一次累积的日志条目,而不是一次发送一个,那就太好了。

Have had some trouble with log4j's SMTPAppender not emailing INFO log entries, I think I've solved that. But now I'm curious if that's the best solution. I'm very frequently emailing based on output of different logfiles. Is there a better solution than SMTPAppender to email? I'd rather not harm performance of my app and the emailing happen asynchronously. And it'd be nice to maybe even email every 5 minutes with the accumulated log entries instead of one at a time as they happen.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

烟沫凡尘 2024-10-12 18:22:13

SMTPAppender 的目的是立即通知您有关关键事件的信息,或者至少在发生 N 个事件时通知您,这就是默认情况下仅邮寄错误日志的原因。 SMTPAppender 类型上还声明了 CyclicBuffer 类型的属性 cb,用它来控制发送之前收集的日志语句的数量。如果应用程序运行在Linux环境中,则使用CRON每5分钟发送一次这些日志语句更为合适。 TaskScheduler 可能有助于在 Windows 平台上实现相同的目标。

Purpose of SMTPAppender is to notify you about critical events promptly or at least when N number of the events had occured, that is why by default only ERROR logs are mailed out. There is also property cb of type CyclicBuffer declared on the SMTPAppender type, use it to control the number of collected log statement before they are sent. If the application is running in Linux environment, it be more appropriate to use CRON to send those log statements every 5 minutes. TaskScheduler may help to achive the same on Windows platform.

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