当我将Rails应用程序上传到Heroku时,我使用heroku日志收到错误
NoMethodError (undefined method `flush' for #<Logger:0x00000005501680>):
2012-12-20T16:20:42+00:00 app[web.1]: app/controllers/application_controller.rb:19:in `block in <class:ApplicationController>'
这是因为
rescue_from 'Exception' do |ex|
Rails.logger.fatal formatted_exception(ex)
Rails.logger.flush
ApplicationController
中的。
我该如何解决?
答案 0 :(得分:3)
Flush是在IO上定义的一种方法,它将缓冲的输出刷新到管道。
鉴于Heroku的多环境设置,他们可能有自己的IO管道实现,可能没有定义刷新。如果没有定义Flush,那么你不需要它是一个相当安全的赌注,它会在接收输入时自动刷新。
怎么样
rescue_from 'Exception' do |ex|
Rails.logger.fatal formatted_exception(ex)
Rails.logger.flush if Rails.logger.respond_to? :flush
P.S。
您可能不应该拯救例外:Why is it a bad style to `rescue Exception => e` in Ruby?