0

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?

4

1 回答 1

2

使用 Exception Notifier 的最佳选择是rescue_fromApplicationController查找所有异常时使用,然后打扰您的日志记录和手动调用 Exception Notifier。

例子:

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

因此,如果控制器在其中一个操作期间出现错误,它将转到此方法,您可以在发送电子邮件之前将其保存到数据库中。

于 2012-10-25T17:21:00.357 回答