Transformation of mail sending class smtpappender of log4j

During the development process, we sometimes need to send important error logs to relevant responsible persons by email, so that errors can be found and solved immediately. If log4j is used, the following configurations are generally made:

log4j.rootLogger = debug,mail

# 发送日志到指定邮件
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
log4j.appender.mail.Threshold=INFO
log4j.appender.mail.BufferSize=10
log4j.appender.mail.From=from@qq.com
log4j.appender.mail.To=to@163.com
log4j.appender.mail.SMTPHost=smtp.qq.com
#发送邮件箱的用户
log4j.appender.mail.SMTPUsername=from@qq.com
#邮箱的授权码
log4j.appender.mail.SMTPPassword=

But I found the standard org. Org apache. log4j. net. Smtpappender has the following problems.

So you can log 4J Configure the cache size in the properties configuration file and add packages that exclude or only care about logging. You can also add multiple configurations for sending mail to send logs under different packages to different responsible persons.

The final configuration is as follows:

log4j.rootLogger = debug,mail

# 发送日志到指定邮件
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
#排除的包(多个包,以英文逗号隔开)
#log4j.appender.mail.excludePackage=com.alibaba.druid
#仅关心的包,一般excludePackage与includePackage任选一即可,多个包以英文逗号隔开
log4j.appender.mail.includePackage=cn.yang.practise.service,cn.yang.practise.controller,com.alibaba.druid
log4j.appender.mail.Threshold=INFO
log4j.appender.mail.BufferSize=16
log4j.appender.mail.From=from@qq.com
log4j.appender.mail.To=to@163.com
log4j.appender.mail.SMTPHost=smtp.qq.com
#发送邮件箱的用户
log4j.appender.mail.SMTPUsername=from@qq.com
#邮箱的授权码
log4j.appender.mail.SMTPPassword=

Transformed and complete org apache. log4j. net. SMTPAppender,AlertLinkedBlockingQueue

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>