首页 > 代码库 > logback配置错误邮件发送

logback配置错误邮件发送

配置logback发送error级别日志到指定邮箱 

需要导入jar包:janino.jar 

 
 1 <property name="smtpHost" value="http://www.mamicode.com/smtp.163.com" />   2     <property name="smtpPort" value="http://www.mamicode.com/25" />   3     <property name="username" value="http://www.mamicode.com/xxx@163.com" />   4     <property name="password" value="http://www.mamicode.com/xxx" />   5     <property name="SSL" value="http://www.mamicode.com/false" />   6     <property name="email_to" value="http://www.mamicode.com/EMAIL-DESTINATION,ANOTHER_EMAIL_DESTINATION" />   7     <property name="email_from" value="http://www.mamicode.com/xxx@163.com" />   8     <property name="email_subject" value="http://www.mamicode.com/【Error】: %logger" />   9   10     <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">  11         <smtpHost>${smtpHost}</smtpHost>  12         <smtpPort>${smtpPort}</smtpPort>  13         <username>${username}</username>  14         <password>${password}</password>  15         <SSL>${SSL}</SSL>  16         <asynchronousSending>false</asynchronousSending>  17         <to>${email_to}</to>  18         <from>${email_from}</from>  19         <subject>${email_subject}</subject>  20         <layout class="ch.qos.logback.classic.html.HTMLLayout" >  21             <pattern>%date%level%thread%logger{0}%line%message</pattern>  22         </layout>  23         <filter class="ch.qos.logback.core.filter.EvaluatorFilter">    24             <evaluator class="ch.qos.logback.classic.boolex.JaninoEventEvaluator">  25                 <expression>  26                     <!-- & encoded as &amp; -->  27                     if(level > WARN &amp;&amp; null != throwable) {  28                         return true;  29                     }  30                     return false;  31                 </expression>    32             </evaluator>    33             <onMatch>ACCEPT</onMatch>    34             <onMismatch>DENY</onMismatch>      35         </filter>  36 </appender>  37 <root level="INFO">  38      <appender-ref ref="EMAIL"/>  39 </root>  

转自:http://superich2008.iteye.com/blog/2070388