博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
让Rails程序出现异常错误等自动发送错误邮件 - exception_notification
阅读量:7003 次
发布时间:2019-06-27

本文共 1326 字,大约阅读时间需要 4 分钟。

hot3.png

第一次配置时,网上资料较乱,走了不少弯路。特在此记录。

配置环境:Ruby 1.9.3  Rails 3.2.2

1.安装 exception_notification  gem

在Gemfile中添加

gem 'exception_notification', '3.0.0'
注:我第一次使用的是最新版本4.0.0,遇到一个错误 undefined method `underscore' for nil:nilclass 无法解决,后来换了3.0.0 就OK了

2.在environment.rb中配置

这是我的environment.rb, 仅供参考

其中HELLOWORLD为你自己的APP名称

# Load the rails applicationrequire File.expand_path('../application', __FILE__)                                             #这里配置 只有非开发环境才发送错误邮件if Rails.env != "development"  HELLOWORLD::Application.config.middleware.use ExceptionNotifier,    :email_prefix => "这是邮件前缀",    :sender_address => %{"Warn!" 发信人邮箱@qq.com},                                                         #收件人 可配置多个    :exception_recipients => ["123456@qq.com","654321@qq.com"],    :delivery_method => :smtp,                                                                      #邮件服务器配置    :smtp_settings => {        :address => "smtp.gmail.com",        :port => "587",        :domain => "gmail.com",        :authentication => "plain",        :user_name => "XXXXX@gmail.com",        :password => "*********",        :enable_starttls_auto => true    }end# Initialize the rails applicationHELLOWORLD::Application.initialize!

3.重启一下Rails程序 如果你是开发环境下测试,注意修改上面的配置

现在 如果程序出现异常 你应该会收到一封错误邮件 包含具体的报错信息

其他的具体使用方法:

转载于:https://my.oschina.net/themorecolor/blog/149626

你可能感兴趣的文章