Rails3 自定义日志记录选项? [英] Rails3 custom logging options?

查看:33
本文介绍了Rails3 自定义日志记录选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Rails3 的最佳实践"自定义日志记录选项是什么?任何人都可以为伐木推荐好的宝石或技术.

What are the "best-practice" custom logging options for Rails3? Can anyone suggest good gems, or techniques, for logging.

一般来说,自定义的、非控制器的、非模型的东西的约定是什么?如果我制作这样的自定义记录器:

In general, what is the convention for custom, non-controller, non-model stuff? If I make a custom logger like this:

#custom_logger.rb
class CustomLogger < Logger
  def format_message(severity, timestamp, progname, msg)
    "#{msg}\n"
  end
end

logfile = File.open(RAILS_ROOT + '/log/custom.log', 'a')  #create log file
logfile.sync = true  #automatically flushes data to file
CUSTOM_LOGGER = CustomLogger.new(logfile)  #constant accessible anywhere

(从此处盗取)) 应该放在/lib"中的文件中吗?在application.rb"中?还是在初始化程序中?

(stolen from here) Should that go in a file in "/lib"? In "application.rb"? Or in an initializer?

我似乎找不到任何描述这些与以前 Rails 版本的细微差别的内容.

I can't seem to find anything that describes these little differences from previous Rails versions.

谢谢

推荐答案

'lib' 似乎仍然是放置这些东西的合适位置.

'lib' still seems to be the proper place to put this stuff.

见:

库在 Rails 3 中应该放在什么位置?

这篇关于Rails3 自定义日志记录选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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