开发者

Exception Notification - How to Shut Off in Dev. Mode

I've been happily using exception notification up till now and never sent an email when running in development mode. Now, the gem seems to want to send me an email whenever an exception occurs -- particularly a routing error. Is there some config setting I'm missin开发者_运维百科g? The dox seem to have dried up and blown away.


Assuming you have an initializer to set up your configuration, just wrap it in a conditional to check if it's in production mode:

if Rails.env.production?
  Whatever::Application.config.middleware.use ExceptionNotifier,
    :email_prefix => "[Whatever] ",
    :sender_address => %{"notifier" <notifier@example.com>},
    :exception_recipients => %w{exceptions@example.com}
end


Part 1: set up different configurations for ExceptionNotifier in your config/environments/environment_name.rb files. For example, in config/environments/development.rb, use something like this to send your notifications elsewhere, or to a black hole:

  YourApp::Application.configure do
    <other stuff>
    config.middleware.use ExceptionNotifier,
      :email_prefix => "[YourApp - DEVELOPMENT:#{`hostname`}] ",
      :sender_address => %{"notifier" <notifier@#{`hostname`}>},
      :exception_recipients => %w{<some_bitbucket_email_address>}
  end

This way, your ExceptionNotifier is still configured in all environments. If it isn't configured, any direct calls to

 ExceptionNotifier::Notifier.background_exception_notification(e).deliver

will throw exceptions, which could be undesired behavior inside a rescue block.

Part 2: try setting this config parameter:

config.consider_all_requests_local = true

I picked that up from the reverse question to this: Exception notifier plugin not sending emails


Rails 3

Is better write the configuration in the production environment, look at my examle

APP::Application.configure do
...
..
.
config.middleware.use ExceptionNotifier,
                   :email_prefix => "[Error] ",
                   :sender_address => %{"Notificacion de error" <notifier@example.com>},
                   :exception_recipients => %w{addres1@email.com}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜