logback发送错误邮件

logback日志预警:
1.maven加入邮件发送jar包

    javax.mail
    mail
    1.4.7


2.logback.xml加入下面代码

     
   
   
   
   
     
    
     
        ${smtpHost}  
        ${username}  
        ${password}  
        ${SSL}  
        ${email_to}  
        ${username}  
        ${email_subject}  
        true
       
          %date %X{ip}  %-5level %logger{35} - %message%n
       

   


   
         
   


3.java代码中log.error打印出来的内容,就会自动发送到邮件中。发送延迟在5秒内



4.加入标记,加入evaluator
   
       
            sendmail
       

        ${smtpHost}  
        ${username}  
        ${password}  
        ${SSL}  
        ${email_to}  
        ${username}  
        ${email_subject}  
        true
       
          %date %X{ip}  %-5level %logger{35} - %message%n
       

   

    打印时候也加入标记
    logger.error(MarkerFactory.getMarker("sendmail"),"预警发送:"+e.getMessage());

5.参考资料

http://logback.qos.ch/manual/appenders.html

你可能感兴趣的:(java)