每天一剂Rails良药之exception_notification

本文介绍了Rails中的ExceptionNotification插件使用方法。该插件能在生产环境中遇到未处理的异常时,向指定收件人发送邮件通知。文章还详细解释了如何配置插件来决定哪些错误需要发送通知,以及如何自定义邮件中的错误信息。
[url=http://hideto.iteye.com/blog/81144]每天一剂Rails良药之Getting Notified of Unhandled Exceptions[/url]中也提到了Exception Notification插件
该插件在production环境下,当程序出错时会给recipient发送notification邮件

Exception notification只会在访问的IP地址不为local时才工作,我们可以配置认为是local的IP:
[code]
consider_local "64.72.18.143", "14.17.21.25"
consider_local "64.72.18.143/24"
[/code]

如果我们要清除本地地址列表,比如想让"127.0.0.1"不被认为是local的,我们可以在controller里加上:
[code]
local_addresses.clear
[/code]

在views/exception_notifier目录下的视图文件可以访问如下变量:
[b]
* @controller: the controller that caused the error
* @request: the current request object
* @exception: the exception that was raised
* @host: the name of the host that made the request
* @backtrace: a sanitized version of the exception's backtrace
* @rails_root: a sanitized version of RAILS_ROOT
* @data: a hash of optional data values that were passed to the notifier
* @sections: the array of sections to include in the email
[/b]

通过修改ExceptionNotifier.sections变量,我们可以添加和排除一些视图
添加视图时,我们只需把新的视图的名字加到ExceptionNotifier.sections列表并定义相应的partial即可
如果新定义的partial需要自定义的变量信息,我们可以使用exception_data宏:
[code]
class ApplicationController < ActionController::Base
...
protected
exception_data :additional_data

def additional_data
{ :document => @document,
:person => @person }
end
...
end
[/code]

默认下email notifier只会对critical errors进行notify
对于ActiveRecord::RecordNotFound和ActionController::UnknownAction只会render你的public/404.html文件
其他异常则会render你的public/500.html并发送email notification
具体规则参考exception_notification的源文件即可
如果你想更改发送email notification的规则,只需实现或修改rescue_action_in_public方法即可
内容概要:本文系统阐述了Python在数据分析与可视化领域的技术实践,涵盖数据分析基础、数据探索方法、可视化技术原理、高级可视化应用及实战案例五大方面。文章首先介绍NumPy和Pandas在数据处理与描述性统计中的核心作用,继而讲解相关性分析、分布分析和分组对比等探索性分析方法。随后深入剖析Matplotlib、Seaborn和Plotly三大可视化库的技术特点与应用场景,涵盖静态图表、统计图形到交互式可视化。最后通过交通数据的实战案例,演示从数据预处理、探索分析到多维度可视化呈现的完整流程。; 适合人群:具备Python基础、对数据处理与可视化感兴趣的初中级开发者,以及从事数据分析、运营分析、数据科学研究等相关工作的人员;尤其适合工作1-3年、希望提升数据实战能力的研发人员。; 使用场景及目标:①掌握Pandas进行数据清洗、分组聚合与描述性统计的方法;②熟练运用Matplotlib、Seaborn和Plotly实现多样化数据可视化;③通过真实案例理解探索性数据分析流程并构建交互式仪表盘;④应用于业务报表开发、数据洞察挖掘和决策支持系统建设。; 阅读建议:建议结合代码实践同步学习,重点理解不同可视化工具的适用边界,并在实战中尝试迁移应用文中案例逻辑,强化对数据分布识别、多维分析和交互设计的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值