Send email on any server (backend) error, handles or unhandled

Hi,

I was just wondering if there is some way to configure server to send any backend exception to a particular support or dev email address.

This will help in pro actively find and fix issues.

Thanks

Hi,

It is possible with logback SMTPAppender: Chapter 4: Appenders

Sample configuration from docs:

<configuration>   
  <appender name="EMAIL" class="ch.qos.logback.classic.net.SMTPAppender">
    <smtpHost>ADDRESS-OF-YOUR-SMTP-HOST</smtpHost>
    <to>EMAIL-DESTINATION</to>
    <to>ANOTHER_EMAIL_DESTINATION</to> <!-- additional destinations are possible -->
    <from>SENDER-EMAIL</from>
    <subject>TESTING: %logger{20} - %m</subject>
    <layout class="ch.qos.logback.classic.PatternLayout">
      <pattern>%date %-5level %logger{35} - %message%n</pattern>
    </layout>       
  </appender>

  <root level="DEBUG">
    <appender-ref ref="EMAIL" />
  </root>  
</configuration>

You can configure it in logback.xml file in your tomcat or WAR file.

1 Like

This works like a charm.

Thanks