将文件名添加到Rails记录器信息消息中 [英] Adding filename to Rails logger info messages

查看:51
本文介绍了将文件名添加到Rails记录器信息消息中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Rails的日志消息中添加文件名和行号?我目前的格式是

How to add the file name and line number in Rails' log message? My current format is something like

[INFO : 12-09-27 10:12:30]

我想将其更改为

[INFO: 12-09-27 10:12:30 application_controller.rb:35]

或类似的东西.有什么想法吗?

or something like this. Any ideas?

推荐答案

config/initializers目录中创建一个初始化程序logger.rb,然后尝试将其放置

Create an initializer logger.rb in your config/initializers directory and try putting this

class Logger::SimpleFormatter
  def call(severity, time, progname, msg)
    "[#{severity} #{time} #{caller(0).first.match(/.*:\d+/)[0]}] #{msg}\n"
  end
end

应该在Ruby 1.9+上工作

Should work on Ruby 1.9+

这篇关于将文件名添加到Rails记录器信息消息中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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