开发者

How do I configure the Airbrake gem to log all Rails exceptions in both development and production environments?

I have found it difficult to send exceptions of my Rails 3 app via the Airbrake gem. At fi开发者_如何学JAVArst I thought there was an Airbrake configuration error on my part, but after trial and error and reading the documentation (https://github.com/thoughtbot/airbrake#readme) very closely, I found out that Airbrake does not report errors when an app is running in the development environment. It does report errors when the app is running in the production environment.

Is there a flag to generate an Airbrake configuration file that automatically includes the development environment in the list of environments in which notifications should not be sent?

Currently I am executing the command listed in the README

script/rails generate airbrake --api-key your_key_here


Straightforward.

  config.consider_all_requests_local       = false

instead of

  config.consider_all_requests_local       = true

in your config/environments/development.rb. In my case, like I suspect in many others, it was just a temporary change so I can "test" Airbrake's notify_airbrake.

You do need config.development_environments = [] in airbrake.rb


Not sure about a config options, but you can explicitly send notifications to Airbrake from a controller using

notify_airbrake(exception)

So to do this in development, you could catch all errors in your application_controller, send a notification and then handle the errors as before. Take a look at rescue_from to get started. This is how I'm doing this to get notifications from my staging environment (or, to be exact, any environment other than development and test).

class ApplicationController < ActionController::Base

  rescue_from Exception, :with => :render_error

  private

  def render_error(exception)
    render :file => "#{Rails.root}/public/500.html", :layout => false, :status => 500
    logger.error(exception)
    notify_airbrake(exception) unless Rails.env.development? || Rails.env.test?
  end
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜