`

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,原来答案在这里:
http://www.ruby-forum.com/topic/149073

所以解决办法有两种,其实都一样:
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

3
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics