如何使用默认的Rails记录器记录Ruby异常的整个跟踪记录? [英] How do I log the entire trace back of a Ruby exception using the default Rails logger?

查看:75
本文介绍了如何使用默认的Rails记录器记录Ruby异常的整个跟踪记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Rails项目上工作,我正在尝试获取要记录到Rails日志文件中的异常.我知道我可以调用logger.error $!将异常的第一行记录到文件中.但是,我也想记录整个跟踪堆栈.如何使用默认的Rails记录器记录异常的整个追溯?

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 exception logged to the file. But, I want to get the entire trace stack logged as well. How do I log the entire trace back of an exception using the default rails logger?

推荐答案

logger.error $!.backtrace

此外,别忘了您可以

rescue ErrorType => error_name

为错误赋予一个变量名称,而不是默认的$!.

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

这篇关于如何使用默认的Rails记录器记录Ruby异常的整个跟踪记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆