在Rails 3中设置记录器 [英] Setting up the logger in rails 3
问题描述
我试图弄清楚如何将记录器与rails 3一起使用.我需要登录到控制台中没有该文件的文件,但是我只是想不出如何设置它,然后如何设置它.在该日志中写一些东西.我尝试了Rails文档,但他们并没有说清楚.
I'm trying to figure out how to use the logger with rails 3. I need to log to a file not have it in the console, but I just can't figure out how to set it up and then, how to write something to that log. I tried the rails docs but they didn't really make it clear.
推荐答案
默认情况下,Rails应该将日志记录到项目的log
目录中的特定于环境的日志文件中.根据您在哪个环境中运行,它将被称为test.log
,development.log
或production.log
.
By default, Rails should be logging to an environment-specific log file in your project's log
directory. It will be called either test.log
, development.log
, or production.log
depending on which environment you're running in.
您可以使用Rails.logger
对象直接登录到Rails的记录器:
You can log directly to Rails' logger using the Rails.logger
object:
Rails.logger.info "My info message"
Rails.logger.debug "My debugging message"
Rails.logger.warn "My warning message"
过去使用 Ruby的标准日志记录类 ,但现在使用 ActiveSupport::BufferedLogger
. (官方 Ruby on Rails指南说"Rails使用Ruby的标准记录器来写日志信息").
Rails used to use Ruby's standard logging class, but it now uses ActiveSupport::BufferedLogger
. (The official Ruby on Rails Guides are incorrect when they say "Rails makes use of Ruby’s standard logger to write log information").
这篇关于在Rails 3中设置记录器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!