问题描述
公司没有专业的运维,但有需要日志报警所以使用了logback的报错通知机制,
亲测可用有什么问题可以留言交流
引入jar包
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<version>2.7.8</version>
</dependency>
配置文件
<!--邮件相关属性-->
<property name="smtpHost" value="smtp.qq.com"/>
<property name="smtpPort" value="465" />
<property name="email_from" value="XXXX@qq.com"/>
<property name="username" value="XXXX@qq.com"/>
<property name="password" value="授权码"/>
<property name="email_to" value="XXXX@163.com"/>
<property name="SSL" value="true" />
<property name="email_subject" value="【Error】【logback-sendmail】: %logger"/>
<!--配置appender-->
<appender name="errMailer" class="ch.qos.logback.classic.net.SMTPAppender">
<cyclicBufferTracker class="ch.qos.logback.core.spi.CyclicBufferTracker">
<bufferSize>1</bufferSize>
</cyclicBufferTracker>
<smtpHost>${smtpHost}</smtpHost>
<smtpPort>${smtpPort}</smtpPort>
<username>${username}</username>
<password>${password}</password>
<SSL>${SSL}</SSL>
<asynchronousSending>false</asynchronousSending>
<to>${email_to}</to>
<from>${email_from}</from>
<subject>${email_subject}</subject>
<layout class="ch.qos.logback.classic.html.HTMLLayout"/>
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
</appender>
<!--根logger控制 -->
<root level="debug">
<appender-ref ref="CONSOLE" />
<!-- <appender-ref ref="INFO_FILE" />
<appender-ref ref="ERROR_FILE" />-->
<appender-ref ref="errMailer" />
</root>
来源:oschina
链接:https://my.oschina.net/ydsakyclguozi/blog/4839853