Problem Statement

Recently, while working on a legacy Ruby on Rails application, I upgraded Rails from 6.1.7.8 to 6.1.7.10. After the upgrade, the application crashed with the following error on boot:
uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)

The rails console worked fine, but running the application or loading the environment failed. This was puzzling, especially since this code worked perfectly fine before the upgrade.

Answer

When I upgraded to Rails 6.1.7.10, it started using a part of the code (LoggerThreadSafeLevel) that assumes the Ruby Logger class is already loaded.

In earlier versions, this worked fine because one of Rails’ dependencies (concurrent-ruby) automatically loaded Logger.

But from version 1.3.5, concurrent-ruby stopped loading Logger by default. So now, if Logger isn’t manually required, Rails throws this error.

Solutions

1. Manually Require the logger Library

Add the following line to the top of your config/application.rb:

require 'logger'
Or add it to config/boot.rb before Rails is loaded:
require 'bundler/setup'
require 'logger'

Why this works: It explicitly loads the Ruby standard Logger class before Rails references it.

2. Pin concurrent-ruby to Version 1.3.4

In your Gemfile:
gem 'concurrent-ruby', '1.3.4'
Then run:
bundle install
Why this works: concurrent-ruby v1.3.4 still autoloads Logger, which avoids the uninitialized constant error.

3. Upgrade Rails to 7.1+ (Long-Term Fix)

Rails 7.1+ has addressed this issue by properly loading the Logger dependency internally. If your application and other gems are compatible with Rails 7, upgrading will prevent this and other legacy compatibility issues.

Why this works: The new version handles logger loading without relying on indirect dependencies.

Need Help With Ruby On Rails Development?

Work with our skilled Ruby on Rails developers to accelerate your project and boost its performance.

Hire Ruby on Rails Developer

Support On Demand!

Related Q&A