log4j将日志输出到控制台,文件,邮件
1 #将日志写到文件 2 log4j.appender.file=org.apache.log4j.DailyRollingFileAppender 3 log4j.appender.file.File=e\:\\log\\zmcc.log 4 log4j.appender.file.DatePattern=yyyy-MM-dd-HH-mm'.log' 5 log4j.appender.file.layout=org.apache.log4j.PatternLayout 6 log4j.appender.file.threshold=error 7 log4j.appender.file.layout.ConversionPattern=[%d] [%t] (%F:%L) %-5p %c - %m%n 8 log4j.appender.file.encoding=UTF-8 9 10 11 log4j.appender.console=org.apache.log4j.ConsoleAppender 12 log4j.appender.console.layout=org.apache.log4j.PatternLayout 13 log4j.appender.console.layout.ConversionPattern=[%d] [%t] (%F:%L) %-5p %c - %m%n 14 log4j.appender.console.encoding=UTF-8 15 16 log4j.appender.html=org.apache.log4j.DailyRollingFileAppender 17 log4j.appender.html.File=log4j.log 18 log4j.appender.html.layout=org.apache.log4j.HTMLLayout 19 20 21 # 将日志发送到email 22 log4j.logger.MailLog=WARN,A5 23 log4j.appender.A5=org.apache.log4j.net.SMTPAppender 24 log4j.appender.A5.BufferSize=5 25 #收件人名称,多个人以逗号隔开 26 log4j.appender.A5.To= 27 #发件人 28 log4j.appender.A5.From= 29 #登录名 30 log4j.appender.A5.SMTPUsername= 31 #邮件密码 32 log4j.appender.A5.SMTPPassword= 33 log4j.appender.A5.Subject=ErrorLog 34 log4j.appender.A5.Encoding=UTF-8 35 log4j.appender.A5.SMTPHost=smtp.exmail.qq.com 36 log4j.appender.MAIL.Threshold=ERROR 37 # 缓存文件大小,日志达到250K时发送Email 38 log4j.appender.MAIL.BufferSize=250 39 log4j.appender.A5.layout=org.apache.log4j.PatternLayout 40 log4j.appender.A5.layout.ConversionPattern=%-4r %-5p [%t] %37c %3x - %m%n 41 42 43 log4j.rootLogger=error,console,A5 44 log4j.logger.com.lzb=debug 45 log4j.logger.com.ibatis=DEBUG,info
发送邮件需要一如两个包:mail.jar,activation.jar
邮件包下载地址:http://pan.baidu.com/s/1c0nWuxa