Exception Notifier Plugin功能:当你的Rails Application出错时,Exception Notifier会向指定的email发送日志
一:安装
[code]ruby script/plugin install exception_notification[/code]
二:使用
1:) 在config/environment.rb增加邮件接收者的地址
[code]ExceptionNotifier.exception_recipients = %w(youremail@domain.com)[/code]
2:) 配置smtp,我们这里采用gmail
[code]ActionMailer::Base.smtp_settings = {
;:address => "smtp.gmail.com",
;:port => 587,
;:domain => "gmail.com",
;:authentication => :plain,
;:user_name => "martin.xus",
;:password => "hello world"
}[/code]
3:) 告诉ExceptionNotifier那些controller出错才发送日志
[code]class ApplicationController < ActionController::Base
include ExceptionNotifiable
end
[/code]
三:配置
我们也许会用到下面两个配置
1:) 修改邮件发送者
[code] ExceptionNotifier.sender_address =%("Application Error"<Exception.Notify@domain.com>)[/code]
2:) 邮件标题前缀
[code]ExceptionNotifier.email_prefix = "[Exception Notify] "[/code]
就这么简单:) 你会用了吗?
四:定制
这个嘛.... 留给你自己去做了:)
附注--注意事项:
1:) ExceptionNotifier默认在production环境下才会生效,如果你想要development也生效,请修改
[code]config.action_mailer.raise_delivery_errors = false
config.action_controller.consider_all_requests_local = true[/code]
为
[code]config.action_mailer.raise_delivery_errors = true
config.action_controller.consider_all_requests_local = false[/code]
试试
2:) 请不要覆盖rescue_action_in_public
http://api.rubyonrails.org/classes/ActionController/Rescue.html
3:) 如果你的站点收到恶意访问,错误的报告也许会很多:)
一:安装
[code]ruby script/plugin install exception_notification[/code]
二:使用
1:) 在config/environment.rb增加邮件接收者的地址
[code]ExceptionNotifier.exception_recipients = %w(youremail@domain.com)[/code]
2:) 配置smtp,我们这里采用gmail
[code]ActionMailer::Base.smtp_settings = {
;:address => "smtp.gmail.com",
;:port => 587,
;:domain => "gmail.com",
;:authentication => :plain,
;:user_name => "martin.xus",
;:password => "hello world"
}[/code]
3:) 告诉ExceptionNotifier那些controller出错才发送日志
[code]class ApplicationController < ActionController::Base
include ExceptionNotifiable
end
[/code]
三:配置
我们也许会用到下面两个配置
1:) 修改邮件发送者
[code] ExceptionNotifier.sender_address =%("Application Error"<Exception.Notify@domain.com>)[/code]
2:) 邮件标题前缀
[code]ExceptionNotifier.email_prefix = "[Exception Notify] "[/code]
就这么简单:) 你会用了吗?
四:定制
这个嘛.... 留给你自己去做了:)
附注--注意事项:
1:) ExceptionNotifier默认在production环境下才会生效,如果你想要development也生效,请修改
[code]config.action_mailer.raise_delivery_errors = false
config.action_controller.consider_all_requests_local = true[/code]
为
[code]config.action_mailer.raise_delivery_errors = true
config.action_controller.consider_all_requests_local = false[/code]
试试
2:) 请不要覆盖rescue_action_in_public
http://api.rubyonrails.org/classes/ActionController/Rescue.html
3:) 如果你的站点收到恶意访问,错误的报告也许会很多:)