Rails2.0.2中rake在production环境不能log

目前的定时任务是用cron + rake。

在rake中使用了log进行相关的信息记录,
rake :test_xxx => :environment do
# some operation
RAILS_DEFAULT_LOGGER.info "It takes #{end_time - start_time} to generate tippay message #{Time.now.to_s(:db)}"
end

在开发环境下发现是正常的,但是在产品环境中怎么也不能log,原来答案在这里:
[url]http://www.ruby-forum.com/topic/149073[/url]

所以解决办法有两种,其实都一样:
1.在rake之前配置RAILS_DEFAULT_LOGGER.auto_flushing = true
2.在rake任务的block块内的最后面加上RAILS_DEFAULT_LOGGER.flush


===========================================
The good news is I've somehow worked around it by putting this as the
first line in all of my rake tasks:

RAILS_DEFAULT_LOGGER.auto_flushing = true

Now I'm seeing all my output again, yay!

But why should I have to do this? I think (but can't prove) that this
broke when I upgraded from 1.2.6 to 2.0.2. But if it was a Rails bug,
I would think this would be biting a lot of people, not just me.

Also I'm concerned about the effect this change will have on
performance, so I hope someone can shed some light here.

Thanks!
Jeff

===================================================
I guess you're asking about "auto_flushing", not "auto_loading"?

In 2.0.2, /railties/lib/initializer.rb, line 254:

http://github.com/github/rails/tree/c8da518bbfedc2a06b1d96912ddae00e57f21748/railties/lib/initializer.rb#L254

logger.auto_flushing = false if configuration.environment ==
"production"

This overwrites the default as set in active_support/buffered_logger,
line 41:

http://github.com/github/rails/tree/c8da518bbfedc2a06b1d96912ddae00e57f21748/activesupport/lib/active_support/buffered_logger.rb#L41

@auto_flushing = 1

By the way: in upcoming releases you'll find an additional different
default:

http://github.com/github/rails/tree/master/railties/lib/initializer.rb#L345-348

if configuration.environment == "production"
logger.auto_flushing = false
logger.set_non_blocking_io
end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值