Log4j配置错误日志邮件发送

jopen 5年前

我们项目中log4j为我们输出很多错误日志,由于没有及时处理,造成系统运行不稳定,所以可以将错误日志通过邮件形式发送给具体开发人员

1.配置log4j.properties

#DEV  log4j.rootLogger =DEBUG,stdout  #RUNING  #log4j.rootLogger =INFO,I,E,A5     # Console output...  log4j.appender.stdout = org.apache.log4j.ConsoleAppender  log4j.appender.stdout.Target = System.out  log4j.appender.stdout.layout = org.apache.log4j.PatternLayout  log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss}||%F||%M||%m%n     # INFO  log4j.appender.I =org.apache.log4j.DailyRollingFileAppender  log4j.appender.I.File =/home/logs/info.log  log4j.appender.I.Append =true  log4j.appender.I.Threshold =info  log4j.appender.I.layout =org.apache.log4j.PatternLayout  log4j.appender.I.layout.ConversionPattern =%d{yyyy-MM-dd HH:mm:ss}||%F||%M||%m%n        # ERROR  log4j.appender.E =org.apache.log4j.DailyRollingFileAppender  log4j.appender.E.File =/home/logs/error.log  log4j.appender.E.Append =true  log4j.appender.E.Threshold =error  log4j.appender.E.layout =org.apache.log4j.PatternLayout  log4j.appender.E.layout.ConversionPattern =%d{yyyy-MM-dd HH:mm:ss} %m%n     #EMAIL   log4j.appender.A5=org.apache.log4j.net.SMTPAppender   log4j.appender.A5.BufferSize=5   log4j.appender.A5.Threshold=error   log4j.appender.A5.To=[被发送者]   log4j.appender.A5.From=[发送者]   log4j.appender.A5.Subject=ErrorLog   log4j.appender.A5.SMTPHost=[STMP服务]   log4j.appender.A5.SMTPUsername=[用户名]   log4j.appender.A5.SMTPPassword=[密码]   log4j.appender.A5.layout=org.apache.log4j.PatternLayout   log4j.appender.A5.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n

来自:http://my.oschina.net/guoenzhou/blog/526626