You can also play extractor tricks here:
object MyExceptionLogger {
def unapply(in: (Props.RunModes.Value, Req, Throwable)):
Option[(Props.RunModes.Value, Req, Throwable)] = {
Mailer.sendMail(From(y...@yaks.com), Subject(You've got exception),
To(firefight...@yaks.com), PlainMailBodyType(in._3.getMessage))
None
}
}
LiftRules.exceptionHandler.prepend{
case MyExceptionLogger(_, _, t) = throw t // this will never happen
}
What this does is it calls the unapply method on MyExceptionLogger which has
the side effect of sending email about the exception, but it returns None so
the case is not applied and the testing continues.
On Thu, Jan 28, 2010 at 11:42 PM, Jeppe Nejsum Madsen je...@ingolfs.dkwrote:
Yu-Shan Fung ambivale...@gmail.com writes:
Hi All,
A bit of a shot in the dark, but is there an easy way to setup email
notification on an lift app whenever an uncaught exception occurs? Seems
like a common enough use-case, just wonder if there's a standard way to
do
it before I roll my own.
I have it setup so that all unhandled exceptions are logged with an
error:
private def setupGlobalErrorHandler() {
val currentHandler = LiftRules.exceptionHandler.toList.first
LiftRules.exceptionHandler.prepend {
case (Props.RunModes.Development, r, e) =
Log.error(Exception occurred during processing of %s.
UserId=%s.format(r,User.currentUserId), e)
currentHandler((Props.RunModes.Development, r, e))
case (Props.RunModes.Production, r, e) =
Log.error(Exception occurred during processing of %s.
UserId=%s.format(r,User.currentUserId), e)
RedirectResponse(/error.html)
}
}
}
I then (in production) configure logback to send me emails on errors:
appender name=EMAIL class=ch.qos.logback.classic.net.SMTPAppender
SMTPHostlocalhost/SMTPHost
Tox...@xxx/To
Fromy...@fyyy/From
layout class=ch.qos.logback.classic.html.HTMLLayout /
/appender
/Jeppe
--
You received this message because you are subscribed to the Google Groups
Lift group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to
liftweb+unsubscr...@googlegroups.comliftweb%2bunsubscr...@googlegroups.com
.
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en.
--
Lift, the simply functional web framework http://liftweb.net
Beginning Scala http://www.apress.com/book/view/1430219890
Follow me: http://twitter.com/dpp
Surf the harmonics
--
You received this message because you are subscribed to the Google Groups
Lift group.
To post to this group, send email to lift...@googlegroups.com.
To unsubscribe from this group, send email to
liftweb+unsubscr...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/liftweb?hl=en.