如果我正在处理应用程序控制器中的错误,则会在日志中打印异常



嗨,我的代码在这里

class ApplicationController < ActionController::Base
  protect_from_forgery
  rescue_from Exception, :with => :error_render_method
   def error_render_method
    respond_to do |type|
      type.html { render :template => "web/static/missing", :status => 404 }
      type.all  { render :nothing => true, :status => 404 }
    end
    true
  end
end

它工作正常,但我也想在日志中打印,如果发生任何错误,我该如何进行

使用logger.warn:

rescue_from Exception do |exception|
   error_render_method(exception)
end
def error_render_method(error)
  logger.warn(error.message)
  respond_to do |type|
    type.html { render :template => "web/static/missing", :status => 404 }
    type.all  { render :nothing => true, :status => 404 }
  end
  true
end

最新更新