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

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

    logger.error $!.backtrace
    

    Also, don't forget you can

    rescue ErrorType => error_name
    

    to give your error a variable name other than the default $!.

提交回复
热议问题