Log4j SmtpAppender - 主题异常
我使用 log4j 发送电子邮件,但有例外。
我的 log4j 配置:
log4j.rootLogger=info, stdout, errmail
log4j.appender.errmail=cz.toby.utils.log.ErrSmtpAppender
[email protected]
log4j.appender.errmail.subject=Error -
log4j.appender.errmail.layout=org.apache.log4j.HTMLLayout
log4j.appender.errmail.threshold=debug
它工作得很好,但我想要的是动态更改带有异常名称的主题内容。
我的附加程序如下所示:
public class ErrSmtpAppender extends SMTPAppender {
@Override
public void activateOptions() {
setSMTPHost("xxxxx");
setFrom("[email protected]");
setBufferSize(50);
super.activateOptions();
try {
msg.setSubject(msg.getSubject() + ", node: " + InetAddress.getLocalHost().getHostName());
} catch (Exception e) {
// do nothing, only cannot set host to subject
}
}
}
如何以编程方式设置带有异常名称的主题?我试图在互联网上找到它,但我只找到了类似的主题,但没有找到我真正想要的。
I use log4j for sending emails with exception.
My log4j configuration:
log4j.rootLogger=info, stdout, errmail
log4j.appender.errmail=cz.toby.utils.log.ErrSmtpAppender
[email protected]
log4j.appender.errmail.subject=Error -
log4j.appender.errmail.layout=org.apache.log4j.HTMLLayout
log4j.appender.errmail.threshold=debug
It works perfectly, but what I want is dynamicaly change the content of subject with names of exceptions.
my appender looks like this:
public class ErrSmtpAppender extends SMTPAppender {
@Override
public void activateOptions() {
setSMTPHost("xxxxx");
setFrom("[email protected]");
setBufferSize(50);
super.activateOptions();
try {
msg.setSubject(msg.getSubject() + ", node: " + InetAddress.getLocalHost().getHostName());
} catch (Exception e) {
// do nothing, only cannot set host to subject
}
}
}
How can I set subject with a name of exception programmatically? I was trying to find it on the internet, but I found only similar themes but not what I exactly want.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@托比好吧,我误解了你想要实现的目标。您想要电子邮件主题中的日志消息吗?
我认为为此,您需要访问 Appender 的 CyclicBuffer cb,例如:
或者您可能还需要执行 ObjectRenderer
@Toby Ok I misunderstood what you are trying to achieve. You are wanting the log message in the e-mail subject?
I think for that you will need to access the CyclicBuffer cb of the Appender something like:
Or you may need to do an ObjectRenderer as well