8

我已按照 Ruby Screencast 指南从 Rails 3.2 升级到 Rails 4。我的测试正在运行并且服务器启动,但是当我发送请求时收到错误消息:

ERROR NoMethodError: undefined method `tagged' for #<Formatter:0x000000057f5dc8>

/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/tagged_logging.rb:67:in `tagged'
/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/rack/logger.rb:21:in `call'
/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/quiet_assets-1.0.2/lib/quiet_assets.rb:18:in `call_with_quiet_assets'
/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/actionpack-4.0.0/lib/action_dispatch/middleware/request_id.rb:21:in `call'
/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.5.2/lib/rack/methodoverride.rb:21:in `call'
/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/activesupport-4.0.0/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/actionpack-4.0.0/lib/action_dispatch/middleware/static.rb:64:in `call'
/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/engine.rb:511:in `call'
/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/railties-4.0.0/lib/rails/application.rb:97:in `call'
/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.5.2/lib/rack/lock.rb:17:in `call'
/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.5.2/lib/rack/content_length.rb:14:in `call'
/home/mahoni/.rvm/gems/ruby-2.0.0-p195/gems/rack-1.5.2/lib/rack/handler/webrick.rb:60:in `service'
/home/mahoni/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/webrick/httpserver.rb:138:in `service'
/home/mahoni/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/webrick/httpserver.rb:94:in `run'
/home/mahoni/.rvm/rubies/ruby-2.0.0-p195/lib/ruby/2.0.0/webrick/server.rb:295:in `block in start_thread'

我已经查看了代码,这对我来说没有意义。它调用logger.tagged. 变量后面的对象logger不是记录器,而是Formatter对象。这很奇怪。

知道是什么原因造成的吗?到目前为止我:

  • 删除了我的Gemfile.lock
  • gem update rails
  • bundle install
  • bundle update

在这个和不同的命令中。我该如何处理?

4

2 回答 2

11

你在使用客户记录器吗?

入住config/environments/development.rb。这就是通常分配记录器的地方。

此外,寻找与config/initializers日志记录相关的猴子补丁。

我正在使用 Chris Powell 的记录器补丁,它导致了一个非常相似的错误。

如果您正在使用该补丁,Rails 4 有一个更新的补丁:http: //cbpowell.wordpress.com/2013/08/09/beautiful-logging-for-ruby-on-rails-4/

于 2013-08-15T18:10:46.787 回答
3

我也有同样的错误,通过重新初始化记录器来摆脱它。

在 config/initializers 上添加了一个新文件,称为 log_formatting.rb

使用此代码:

Rails.logger = ActiveSupport::Logger.new "log/mylog.log"
Rails.logger.formatter = proc{|severity,datetime,progname,msg|
    "[#{datetime.strftime("%Y-%m-%d %H:%M:%S")}] [#{severity}]: #{msg}\n"
}
于 2014-10-21T12:00:58.693 回答