如何配置Airbrake gem以在开发和生产环境中记录所有Rails异常?

Ala*_*cia 10 error-logging ruby-on-rails exception hoptoad

我发现很难通过Airbrake gem发送我的Rails 3应用程序的例外.起初我认为我的Airbrake配置错误,但经过反复试验并非常仔细地阅读文档(https://github.com/thoughtbot/airbrake#readme),我发现Airbrake没有报告错误当应用程序在开发环境中运行时.当应用程序在生产环境中运行时,它会报告错误.

是否有生成Airbrake配置文件的标志,该文件会自动将开发环境包含在不应发送通知的环境列表中?

目前我正在执行README中列出的命令

script/rails generate airbrake --api-key your_key_here
Run Code Online (Sandbox Code Playgroud)

Stu*_* mc 18

直截了当.

  config.consider_all_requests_local       = false
Run Code Online (Sandbox Code Playgroud)

代替

  config.consider_all_requests_local       = true
Run Code Online (Sandbox Code Playgroud)

在你的config/environments/development.rb.在我的情况下,就像我在许多其他人中所怀疑的那样,这只是一个暂时的改变,所以我可以"测试"Airbrake的notify_airbrake.

你需要config.development_environments = []在airbrake.rb

  • 我应该指出,除此之外你还需要`airbrake.rb`中的`config.development_environments = []`! (20认同)

Thi*_*ilo 14

不确定配置选项,但您可以使用控制器向Airbrake明确发送通知

notify_airbrake(exception)
Run Code Online (Sandbox Code Playgroud)

因此,要在开发中执行此操作,您可以捕获application_controller中的所有错误,发送通知,然后像以前一样处理错误.看一下rescue_from即可开始使用.这就是我这样做以从我的登台环境(或者,确切地说,除了开发和测试之外的任何环境)获取通知的方式.

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
Run Code Online (Sandbox Code Playgroud)