Rails日志文件中的输出行号 [英] Output line number in Rails log file

查看:144
本文介绍了Rails日志文件中的输出行号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从调试的 Rails指南,我发现我可以自定义输出到我的日志文件使用这种简单的方法:

From the Rails Guide on debugging, I found that I can customize output to my log files using this simple method:

logger.debug "Person attributes hash: #{@person.attributes.inspect}"

我决定使用它来跟踪变量如何变化并进行流量控制。

I decided use this to track how a variable changes and goes through flow control.

我希望能够看到我的代码的行号,其中调用了 logger#debug 方法。这样的一个例子:

I would like to be able to see the line number of my code where logger#debug method was called. Something like this:

logger.debug "Person attributes hash: #{@person.attributes.inspect} from line #{LINE_NUMBER_VAR}"


推荐答案

logger.debug "Person attributes hash: #{@person.attributes.inspect} from line #{__LINE__}"

这篇关于Rails日志文件中的输出行号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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