【问题标题】:Exception notifier only in Production mode?仅在生产模式下的异常通知器?
【发布时间】:2012-04-30 09:44:33
【问题描述】:

我使用 Exception Notifier 来处理我的应用程序和/config/initializers/exception_notification.rb 中的错误,我有以下内容:

MyAPP::Application.config.middleware.use ExceptionNotifier,
  :email_prefix => "[ERROR] ",
  :sender_address => '"Notifier" <notifier@yourdomain.com>',
  :exception_recipients => ['account@gmail.com']

但是通知邮件也是在开发模式下发送的,如何才能只在生产模式下发送邮件?

【问题讨论】:

    标签: ruby-on-rails-3 exception-handling


    【解决方案1】:

    您可以为每个环境单独配置 ExceptionNotifier。 See also the documentation.

    从 Rails 3 开始,ExceptionNotification 被用作机架中间件,所以 您可以在 config.ru 文件或 您希望它运行的环境。在大多数情况下,你会想要 在生产环境中运行的 ExceptionNotification。

    所以你只需在 config/environments/production.rb 中配置它,例如

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

    还有a nice blog entry handling this topic

    【讨论】:

      猜你喜欢
      • 2017-12-23
      • 2019-11-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-24
      • 2012-10-11
      相关资源
      最近更新 更多