Real-time Mailing Error Logs

I want my Grails web application to send an email for every exception that reaches the end user.

I'm basically looking for an elegant way to achieve something equivalent:

try { // ... all logic/db-access/etc required to render the page is executed here ... } catch (Exception e) { sendmail(" exception@example.com ", "An exception was thrown while processing a http-request", e.toString); } 
+4
source share
3 answers

Turns out this exact question was answered on the Grails mailing list a couple of days ago.

The solution is to add the following to the Config.groovy log4j section:

 log4j { ... appender.mail='org.apache.log4j.net.SMTPAppender' appender.'mail.To'=' email@example.com ' appender.'mail.From'=' email@example.com ' appender.'mail.SMTPHost'='localhost' appender.'mail.BufferSize'=4096 appender.'mail.Subject'='App Error' appender.'mail.layout'='org.apache.log4j.PatternLayout' appender.'mail.layout.ConversionPattern'='[%r] %c{2} %m%n' rootLogger="error,stdout,mail" ... // rootLogger="error,stdout" (old rootLogger) } 

Plus adding sun-javamail.jar and activation.jar to the lib / folder.

+6
source

Assuming you can do this from groovy, you want to use a logging framework like log4j , which has loggers that can add log data to the database, send email , etc.

0
source

You can also take a look at the exceptionHandler mechanism provided by Grails; I find it very simple; but powerful enough to take care of all my individual and clean exception handling requirements. I have not tested this approach since 1.1; but works great with 1.0.3.

 class BootStrap { def exceptionHandler def init = { servletContext -> exceptionHandler.exceptionMappings = [ 'NoSuchFlowExecutionException' :'/myControler/myAction', 'java.lang.Exception' : '/myController/generalAction'] } def destroy = { } } 

A detailed blog is here:

http://blog.bruary.net/2008/03/grails-custom-exception-handling.html

0
source

All Articles