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

后端 未结 7 711
爱一瞬间的悲伤
爱一瞬间的悲伤 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:09

    Here's how I would do it:

    http://gist.github.com/127708

    Here's the ri documentation for Exception#backtrace:

    http://gist.github.com/127710

    Note that you could also use Kernel#caller, which gives you the full trace (minus the curent frame) as well.

    http://gist.github.com/127709

    Also - Note that if you are trying to catch all exceptions, you should rescue from Exception, not RuntimeError.

提交回复
热议问题