# 发送日志到指定邮件
log4j.appender.mail=org.apache.log4j.net.SMTPAppender
log4j.appender.mail.Threshold=DEBUG
log4j.appender.mail.BufferSize=10
log4j.appender.mail.From=xx@qq.com
log4j.appender.mail.SMTPHost=smtp.qq.com
#发送邮件箱的用户
log4j.appender.mail.SMTPUsername=xx@qq.com
#发送邮件箱的密码
log4j.appender.mail.SMTPPassword=xxxxxx
#mail服务器端口,qq为587
log4j.appender.mail.SMTPPort=587
log4j.appender.mail.Subject=Log4J Message
log4j.appender.mail.To=xx@qq.com
log4j.appender.mail.layout=org.apache.log4j.PatternLayout
log4j.appender.mail.layout.ConversionPattern=%d %-5p [%t] (%c{1}:%L) - %m%n
### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=debug, mail
修改Log4j的SMTP默认级别
Log4j的SMTP的级别默认是ERROR级别,只有logger.error("");,才可以收到邮件。不过可以自定义的级别,继承TriggeringEventEvaluator类,覆盖里面的一个方法:
public boolean isTriggeringEvent(LoggingEvent arg0) { return arg0.getLevel().isGreaterOrEqual(Level.INFO); }