I’d like my Grails web-app to send an e-mail for each exception that reaches the end-user.
Basically I’m looking for a elegant way to achieve something equivalent to:
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); }
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 log4j-section of Config.groovy:
Plus adding sun-javamail.jar and activation.jar to the lib/-folder.