Reputation: 6267
We have exception notifier set up on our server, though would like a back-up solution, if the email server is down, that would let us log exceptions in the database.
How is exception notifier listening to every method call and can I listen too?
Or.. is there a gem that already does both sending emails and logging to the database for exceptions?
Upvotes: 0
Views: 499
Reputation: 11647
Your best bet, using Exception Notifier, would be to use rescue_from
within your ApplicationController
looking for all exceptions, then do bother your logging and a manual call to Exception Notifier.
Example:
class ApplicationController < ActionController::Base
rescue_from Exception, :with => :log_and_notify
def log_and_notify(error)
# Save to the DB
# This manual call example is straight from the Exception Notifier github page.
ExceptionNotifier::Notifier.exception_notification(request.env, exception, :data => {:message => "was doing something wrong"}).deliver
end
end
So if a controller gets an error during one of it's actions, it will go to this method, and you can save it to the DB before delivering the email.
Upvotes: 2