Skip to content

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:

plaintext
uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)

The full error trace typically begins with:

plaintext
/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:

  1. concurrent-ruby gem v1.3.5 removed its dependency on Ruby's standard logger library
  2. Older Rails versions (<7.1) implicitly depended on concurrent-ruby to load the logger constant
  3. Rails' LoggerThreadSafeLevel module tries to reference the missing Logger 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+

Solution 1: Require Logger Explicitly (Best Practice)

Add a direct require for Ruby's logger in your boot configuration:

  1. Open config/boot.rb
  2. Add require "logger" immediately after bundler/setup:
ruby
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:

ruby
gem 'concurrent-ruby', '1.3.4'

Then run:

bash
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:

bash
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:

  1. Navigate to Rails' ActiveSupport gem directory:
    bash
    cd /Library/Ruby/Gems/2.6.0/gems/activesupport-6.1.7.10/lib/active_support
  2. Edit logger_thread_safe_level.rb
  3. 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 since logger 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 than boot.rb

Conclusion

When encountering the uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger error, you have two ideal solutions:

  1. Permanent fix: Add require "logger" to config/boot.rb
  2. 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.