Resolving uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger in Rails
Problem Statement
After updating Rails to version 6.1.7.10 (or older Rails versions below 7.1), you may encounter this error during application startup:
uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)
The full error trace typically begins with:
/home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger_thread_safe_level.rb:16:in
`module:LoggerThreadSafeLevel': uninitialized constant
ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)
This issue occurs immediately after a bundle update
and prevents your Rails application from starting, though Rails console may still function.
Root Cause
The error occurs because:
- concurrent-ruby gem v1.3.5 removed its dependency on Ruby's standard
logger
library - Older Rails versions (<7.1) implicitly depended on
concurrent-ruby
to load thelogger
constant - Rails'
LoggerThreadSafeLevel
module tries to reference the missingLogger
constant
This creates a dependency gap when both conditions are met:
- Using Rails 6.1.x or 7.0.x
- Updated to concurrent-ruby 1.3.5+
Recommended Solutions
Solution 1: Require Logger Explicitly (Best Practice)
Add a direct require for Ruby's logger in your boot configuration:
- Open
config/boot.rb
- Add
require "logger"
immediately afterbundler/setup
:
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
require "bundler/setup"
require "logger" # Add this line - fixes the Logger constant
require "bootsnap/setup" # Optional if you use bootsnap
This approach:
- Fixes the missing constant without locking gem versions
- Uses Ruby's built-in logger (no additional gems needed)
- Works for all environments (development/test/production)
Solution 2: Pin concurrent-ruby Version (Temporary Fix)
Add this to your Gemfile
if you prefer version pinning:
gem 'concurrent-ruby', '1.3.4'
Then run:
bundle update concurrent-ruby
This works because v1.3.4 still loads the logger
dependency. Note that this solution:
- May conflict with future gem updates
- Is less ideal than Solution 1 for long-term maintenance
- Still requires
bundle install
to downgrade
Solution 3: Upgrade Rails (Long-Term Solution)
For projects able to upgrade:
bundle update rails
Ensure you're running Rails 7.1 or newer, where this was fixed in commit 0f5e7a6. Rails 7.1+ loads logger
explicitly.
Additional Context
For MacOS Users
If adding require "logger"
to boot.rb
doesn't resolve the issue:
- Navigate to Rails' ActiveSupport gem directory:bash
cd /Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.7.10/lib/active_support
- Edit
logger_thread_safe_level.rb
- Add
require "logger"
at the top:ruby# frozen_string_literal: true require "logger" require "active_support/concern" # ... existing requires
WARNING
This directly modifies gem files—changes will be lost on gem reinstallation. Prefer this only as a last resort.
Why You Should Avoid Irrelevant Solutions
- ✘ Adding
gem 'logger'
- Unnecessary sincelogger
is in Ruby's standard library - ✘ Global Ruby upgrades/changes - Not required for this Rails-specific dependency issue
- ✘ Modifying
config/application.rb
- Adding requires here is less reliable thanboot.rb
Conclusion
When encountering the uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger
error, you have two ideal solutions:
- ✅ Permanent fix: Add
require "logger"
toconfig/boot.rb
- ✅ Version constraint: Pin
gem 'concurrent-ruby'
, '1.3.4' in Gemfile
For new projects or upgradable codebases, moving to Rails 7.1+ prevents this issue entirely. The explicit require solution is recommended for most cases as it resolves the underlying dependency gap without affecting other gems.