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_fromしてからApplicationController、ロギングと 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

そのため、アクションのいずれかでコントローラーがエラーを受け取った場合、コントローラーはこのメソッドに移動し、電子メールを配信する前に DB に保存できます。

于 2012-10-25T17:21:00.357 に答える