LoginSignup
2
2

More than 5 years have passed since last update.

Rails4にアップグレードするとLog4rでエラーになる

Posted at
  • Rails3.2系からRails4.0.13にアップグレードするとLog4rでエラーになる
[hoge@CS-c014 4.0_app]$ rs
=> Booting WEBrick
=> Rails 4.0.13 application starting in hogeopment on http://0.0.0.0:3000
=> Run `rails server -h` for more startup options
=> Ctrl-C to shutdown server
Exiting
/home/hoge/.rbenv/versions/2.2.3/gemsets/4.0rails/gems/railties-4.0.13/lib/rails/commands/server.rb:78:in `start': undefined method `formatter' for #<Log4r::Logger:0x007f00bbcd6dc0> (NoMethodError)
        from /home/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/railties-4.0.13/lib/rails/commands.rb:76:in `block in <top (required)>'
        from /home/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/railties-4.0.13/lib/rails/commands.rb:71:in `tap'
        from /home/hoge/.rbenv/versions/2.2.3/gemsets/4.0/gems/railties-4.0.13/lib/rails/commands.rb:71:in `<top (required)>'
        from bin/rails:4:in `require'
        from bin/rails:4:in `<main>'
  • railties-4.0.13/lib/rails/commands/server.rb
    • Rails.loggerにformatterメソッドが無くてエラーになっている
    • loggerはLog4r::Loggerを使っている
server.rb
 77         console = ActiveSupport::Logger.new($stdout)
 78         console.formatter = Rails.logger.formatter
 79         console.level = Rails.logger.level
  • config/initializersの下にlog_format.rbを作成し以下メソッドを書くとエラーにならなくなる。
log_format.rb
class Log4r::Logger
  def formatter
  end
end
  • 一時的な対処のような…後々問題出そう。もっといい方法がありましたら教えてください。
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2