How do I log the entire trace back of a Ruby exception using the default Rails logger?

后端 未结 7 701
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-31 08:29

I am working on rails project and I am trying to get exceptions to be logged to the rails log files. I know I can call logger.error $! to get the first line of the

7条回答
  •  梦如初夏
    2021-01-31 09:11

    In Rails, ActionController::Rescue deals with it. In my application controller actions, i'm using method log_error from this module to pretty-format backtrace in logs:

    def foo_action
      # break something in here
    rescue
      log_error($!)
      # call firemen
    end
    

提交回复
热议问题