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 3中的日志记录器。我需要登录到一个不在控制台的文件,但是我不知道如何设置它然后,如何写一些东西到那个日志。我尝试了rails文档,但它们并没有真正说明问题。
1 个解决方案
#1
80
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应该在项目的日志目录中记录到特定于环境的日志文件。它将被称为任一测试。日志,发展。日志,或生产。根据正在运行的环境进行日志记录。
You can log directly to Rails' logger using the Rails.logger
object:
您可以使用Rails直接登录到Rails的日志记录器。日志记录器对象:
Rails.logger.info "My info message"
Rails.logger.debug "My debugging message"
Rails.logger.warn "My warning message"
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过去使用Ruby的标准日志类,但现在它使用ActiveSupport: BufferedLogger。(官方的Ruby on Rails指南说“Rails使用Ruby的标准日志记录器来编写日志信息”是错误的)。
#1
80
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应该在项目的日志目录中记录到特定于环境的日志文件。它将被称为任一测试。日志,发展。日志,或生产。根据正在运行的环境进行日志记录。
You can log directly to Rails' logger using the Rails.logger
object:
您可以使用Rails直接登录到Rails的日志记录器。日志记录器对象:
Rails.logger.info "My info message"
Rails.logger.debug "My debugging message"
Rails.logger.warn "My warning message"
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过去使用Ruby的标准日志类,但现在它使用ActiveSupport: BufferedLogger。(官方的Ruby on Rails指南说“Rails使用Ruby的标准日志记录器来编写日志信息”是错误的)。