Log4J SMTP 摘要/聚合电子邮件?
我有一个 JBOSS 批处理应用程序,有时会在一分钟内向同一电子邮件地址发送数百封电子邮件,并出现 Log4J 错误。这会导致 Gmail 出现问题,因为它表示我们为该 Gmail 帐户发送电子邮件的速度太快。
所以我想知道是否有一种方法可以基本上创建一封“摘要”或“聚合”电子邮件,将所有错误日志放入一封电子邮件中,并每 5 分钟发送一次。这样一来,每 5 分钟我们可能会收到一封大电子邮件,但至少我们确实收到了电子邮件,而不是因为 gmail 服务器拒绝而延迟了几个小时。
我阅读了这篇文章,其中建议了一些有关使用评估器来做到这一点,但我看不到它是如何在 Log4J xml 配置文件中配置的。无论如何,它似乎也无法将所有日志“消化”到一封电子邮件中。
以前有人这样做过吗?或者知道是否可以?
I have a JBOSS batch application that sometimes sends hundreds on emails in a minute to the same email address with Log4J errors. This causes problems with Gmail, because it says we are sending emails too quickly for that gmail account.
So I was wondering if there was a way to basically create a "digest" or "aggregate" email puts all the error logs in 1 email and sends that every 5 minutes. So that way every 5 minutes we may get a large email, but at least we actually get the email instead of it being delayed for hours and hours by gmail servers rejecting it.
I read this post that suggested something about using an evaluator to do that, but I couldn't see how that is configured in the Log4J xml configuration file. It also seemed like it might not be able to "digest" all the logs into 1 email anyway.
Has anyone done this before? Or know if it's possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自(已存档)SMTPAppender 使用页面:
设置此属性
现在您必须创建评估器类并实现 org.apache.log4j.spi.TriggeringEventEvaluator 接口,并将此类放置在 log4j 可以访问的路径中访问它。
您必须在此方法中编写评估器逻辑。
From (the archived) SMTPAppender Usage page:
set this property
Now you have to create the evaluator class and implement the
org.apache.log4j.spi.TriggeringEventEvaluator
interface and place this class in a path where log4j can access it.You have to write the evaluator logic within this method.
我使用
ExtendedSmtpAppender
为 log4j2 创建了一个免费可用的解决方案。(如果您仍然使用 log4j 1.x,只需将
log4j-1.x.jar
替换为log4j-1.2-api-2.x.jar
- 和log4j-core-2.x.jar
+log4j-api-2.x.jar
当然。)您可以从 Maven Central 获取它
de.it-tw:log4j2-extras
(这需要 Java 7+ 和 log4j 2.8+)。如果您仅限于 Java 6(因此 log4j 2.3),则使用
de.it-tw:log4j2-Java6-extras
此外,请参阅 GitLab 项目:https://gitlab.com/thiesw/log4j2-extras (或 https://gitlab.com/thiesw/log4j2-Java6-extras)
[旧文本:
如果您使用 log4j2,请参阅其他堆栈溢出问题的答案:https://stackoverflow.com/a/34072704/5074004
或者直接转到 https 中提供的外部但公开可用的解决方案://issues.apache.org/jira/browse/LOG4J2-1192
]
I created a free useable solution for log4j2 with an
ExtendedSmtpAppender
.(If you still use log4j 1.x, simply replace your
log4j-1.x.jar
withlog4j-1.2-api-2.x.jar
- andlog4j-core-2.x.jar
+log4j-api-2.x.jar
of course.)You get it from Maven Central as
de.it-tw:log4j2-extras
(This requires Java 7+ and log4j 2.8+).If you are restricted to Java 6 (and thus log4j 2.3) then use
de.it-tw:log4j2-Java6-extras
Additionally, see the GitLab project: https://gitlab.com/thiesw/log4j2-extras (or https://gitlab.com/thiesw/log4j2-Java6-extras)
[OLD text:
If you use log4j2, see answer to other stack overflow issue: https://stackoverflow.com/a/34072704/5074004
Or directly go to my external but publically available solution presented in https://issues.apache.org/jira/browse/LOG4J2-1192
]