RAILS 4.0 中 Log4r 的未定义方法格式化程序 [英] Undefined Method Formatter for Log4r in RAILS 4.0

查看:44
本文介绍了RAILS 4.0 中 Log4r 的未定义方法格式化程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将 Rails 从 3.1.2 升级到 4.0 后,我收到此错误.使用 rails 启动我的服务器时,我遇到了以下错误

I am getting this error after upgrading Rails from 3.1.2 to 4.0. When launching my server with rails s I got stuck with the following error

C:/ruby-2.0.0/lib/ruby/gems/2.0.0/gems/railties-4.0.0/lib/rails/commands/server.rb:78:in `start': undefined method `formatter' for #<Log4r::Logger:0x26dd908> (NoMethodError)

我一直在 Log4r 站点上,但没有任何关于升级 Rails 时错误的信息.

I have been on the Log4r site but haven't got any infor;ation about a bug when upgrading Rails.

有没有人知道这个错误是从哪里来的.谢谢!

Does anyone have any idea where this bug comes from. Thank you!

推荐答案

formatter 方法不是在 Log4r::Logger 上定义的,而是在 Log4r 上定义的::FileOutputter.因此,我很惊讶在 Rails 更新之前工作.也许在不同版本的 Log4r 之间有所不同.

The method formatter is not defined on Log4r::Logger, but on Log4r::FileOutputter. Therefore I am surprised that is worked before the Rails update. Perhaps that changed between different versions of Log4r.

请尝试以下操作(调整文件名和格式):

Please try the following (with adjusted filenames and patters):

require 'log4r'
outputter = Log4r::FileOutputter.new('log4r', filename: 'foobar.log')
outputter.formatter = Log4r::PatternFormatter.new(
  date_pattern: "%FT%T.000Z", pattern: "%d [%l] %m"
)

logger = Log4r::Logger.new('log4r')
logger.outputters = [outputter]

将此代码添加到 config/application.rb 或像 config/initializers/logger.rb

Add this code to config/application.rb or to a new file like config/initializers/logger.rb

这篇关于RAILS 4.0 中 Log4r 的未定义方法格式化程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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