根据日志级别触发电子邮件到不同的 ID
我创建了一个具有不同级别日志记录的应用程序。现在我遇到了向开发团队记录错误并对开发和管理员记录致命错误的情况。这是我尝试过的代码..
log4j.rootlogger=DEBUG, email, email2
#email
log4j.appender.email=org.apache.log4j.net.SMTPAppender
log4j.appender.email.SMTPHost=smtp.company.com
log4J.appender.email.Threshold=error
log4j.appender.email.From=emailNotification
[email protected]
[email protected]
log4j.appender.email.Subject=email Notification from Tomcat Server
log4j.appender.email.layout=org.apache.log4j.PatternLayout
log4j.appender.email.layout.ConversionPattern=%d%d{dd MMM HH:mm:ss}%p %t %c - %m%n
log4j.appender.email.BufferSize=1
#email2
log4j.appender.email2=org.apache.log4j.net.SMTPAppender
log4j.appender.email2.SMTPHost=smtp.company.com
log4J.appender.email2.Threshold=FATAL
log4j.appender.email2.From=emailNotification
[email protected], [email protected]
[email protected]
log4j.appender.email2.Subject=email Notification from Tomcat Server
log4j.appender.email2.layout=org.apache.log4j.PatternLayout
log4j.appender.email2.layout.ConversionPattern=%d%d{dd MMM HH:mm:ss}%p %t %c - %m%n
log4j.appender.email2.BufferSize=1
当我运行我的应用程序时,
logger.error("error:"+e);
它也会触发发送给管理员和经理的电子邮件。因此,即使它是错误/致命的,它也会触发所有人。
有什么窍门吗?有人可以帮助我吗?
I created an application with different levels of logging. Now I got into a situation to log errors to dev team and fatal to dev and admin. here is the code I had given a try..
log4j.rootlogger=DEBUG, email, email2
#email
log4j.appender.email=org.apache.log4j.net.SMTPAppender
log4j.appender.email.SMTPHost=smtp.company.com
log4J.appender.email.Threshold=error
log4j.appender.email.From=emailNotification
[email protected]
[email protected]
log4j.appender.email.Subject=email Notification from Tomcat Server
log4j.appender.email.layout=org.apache.log4j.PatternLayout
log4j.appender.email.layout.ConversionPattern=%d%d{dd MMM HH:mm:ss}%p %t %c - %m%n
log4j.appender.email.BufferSize=1
#email2
log4j.appender.email2=org.apache.log4j.net.SMTPAppender
log4j.appender.email2.SMTPHost=smtp.company.com
log4J.appender.email2.Threshold=FATAL
log4j.appender.email2.From=emailNotification
[email protected], [email protected]
[email protected]
log4j.appender.email2.Subject=email Notification from Tomcat Server
log4j.appender.email2.layout=org.apache.log4j.PatternLayout
log4j.appender.email2.layout.ConversionPattern=%d%d{dd MMM HH:mm:ss}%p %t %c - %m%n
log4j.appender.email2.BufferSize=1
when I run my application with
logger.error("error:"+e);
it was triggering email to admin and manager also. so even it is error/fatal it is triggering to all.
any trick? can someone help me.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
“log4J.appender.email2.Threshold”中有一个拼写错误(字母 J 大写)。 ERROR 是默认值,因此在 email1 中并不重要。
万一有人复制粘贴此代码片段...
There is a typo in "log4J.appender.email2.Threshold" (letter J is in CAPS). ERROR is the default value, so it doesn't matter in the email1.
In case someone is copy-pasting this code snippet...