根据日志级别触发电子邮件到不同的 ID

发布于 2024-12-04 19:18:31 字数 2182 浏览 0 评论 0原文

我创建了一个具有不同级别日志记录的应用程序。现在我遇到了向开发团队记录错误并对开发和管理员记录致命错误的情况。这是我尝试过的代码..

    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 技术交流群。

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

发布评论

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

评论(1

转瞬即逝 2024-12-11 19:18:31

“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...

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