trigger email to different ids depend on loglevel
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
log4j.appender.email.To=dev@company.com
log4j.appender.email.SMTPUsername=user@company.com
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=ema开发者_Python百科ilNotification
log4j.appender.email2.To=admin@company.com, manager@company.com
log4j.appender.email2.SMTPUsername=user@company.com
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.
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...
精彩评论