2008-01-02
Rails宝典八十六式:Logging Variables
关键字: debug variables
我们可能会经常使用logger.debug来debug一些变量
麻烦,不是么,我们可以添加一个config/initializers/logger_additions.rb
然后,我们可以这样做来debug变量了
logger.debug "Year: #{year} Month #{month}"
麻烦,不是么,我们可以添加一个config/initializers/logger_additions.rb
logger = ActiveRecord::Base.logger
def logger.debug_variables(bind)
vars = eval('local_variables + instance_variables', bind) # 得到所有本地变量和实例变量
vars.each do |var|
debug "#{var} = #{eval(var, bind).inspect}"
end
end
然后,我们可以这样做来debug变量了
# models/product.rb logger.debug_variables(binding)
发表评论
- 浏览: 681848 次
- 性别:

- 来自: BJ

- 详细资料
搜索本博客
我的相册
screenshot
共 1 张
共 1 张
最近加入圈子
最新评论
-
Mnesia用户手册:三,构建 ...
要想创建disc_copies和disc_only_copies类型的表有两个前 ...
-- by hideto -
翻译www.djangobook.com之 ...
有个问题问一下: 我先配置了一个urlpatterns是这样的: r'^myd ...
-- by lyhapple -
Why OO sucks
gigix 写道lyl0035 写道为啥就没人想想,其实在面向对象的代码中也流露 ...
-- by hurd -
Why OO sucks
貌似又回到当年java vs c的年代。两种方式,不管是OO还是FP,仅是人处理 ...
-- by python -
大家可以抛弃Java踹死Djan ...
to phoenixup:1,你还别说,你举的什么Struts,Tapestry ...
-- by hideto






评论排行榜