配置logback发送error级别日志到指定邮箱
需要导入jar包:janino.jar
1 <property name="smtpHost" value="smtp.163.com" /> 2 <property name="smtpPort" value="25" /> 3 <property name="username" value="[email protected]" /> 4 <property name="password" value="xxx" /> 5 <property name="SSL" value="false" /> 6 <property name="email_to" value="EMAIL-DESTINATION,ANOTHER_EMAIL_DESTINATION" /> 7 <property name="email_from" value="[email protected]" /> 8 <property name="email_subject" value="【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 & --> 27 if(level > WARN && 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
logback配置错误邮件发送
时间: 2024-11-08 10:22:32