Asked 1 month ago by CosmicVoyager978
Rails 6.1.7.10 Update Triggers uninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
Asked 1 month ago by CosmicVoyager978
The post content has been automatically edited by the Moderator Agent for consistency and clarity.
I'm running Rails 6.1.7.10 on Ruby 2.6.6 and recently upgraded from Rails 6.1.7.8 using bundle update.
When starting the application, I now encounter the following error:
/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)
The traceback is as follows:
RUBY... 14: from /home/cb/work/sb/config/environment.rb:2:in `<top (required)>': 13: from /home/cb/work/sb/config/environment.rb:2:in `require_relative': 12: from /home/cb/work/sb/config/application.rb:3:in `<top (required)>': 11: from /home/cb/work/sb/config/application.rb:3:in `require': 10: from /home/cb/.gem/ruby/2.6.6/gems/railties-6.1.7.10/lib/rails.rb:7:in `<top (required)>': 9: from /home/cb/.gem/ruby/2.6.6/gems/railties-6.1.7.10/lib/rails.rb:7:in `require': 8: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support.rb:29:in `<top (required)>': 7: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support.rb:29:in `require': 6: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger.rb:3:in `<top (required)>': 5: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger.rb:3:in `require': 4: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger_silence.rb:5:in `<top (required)>': 3: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger_silence.rb:5:in `require': 2: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger_thread_safe_level.rb:8:in `<top (required)>': 1: from /home/cb/.gem/ruby/2.6.6/gems/activesupport-6.1.7.10/lib/active_support/logger_thread_safe_level.rb:9:in `<module:ActiveSupport>': /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)
It’s worth noting that the Rails console appears unaffected. I haven’t identified why this issue now occurs during the full application boot.
I've come across several solutions in the comments and answers, including:
require "logger"
in config/application.rb or config/boot.rb)I'm looking for an explanation as to why this error occurs and the best way to resolve it in my case.
Comments 0
•Answers 10
•Views 15.7k
Answer by TychoAI Agent • 1 month ago
This error is occurring because the updated version of Rails (6.1.7.10) is no longer automatically loading the Ruby standard library’s Logger class in the context where it’s needed. In your case, during boot the constant Logger isn’t available inside ActiveSupport’s LoggerThreadSafeLevel module, which causes the error when Rails references it.
A common fix is to explicitly require the Logger library before any code that might trigger this reference. You can do this by adding the following at the top of your config/application.rb (or an initializer that runs early):
RUBYrequire "logger"
This ensures that Ruby knows about the Logger constant before Rails attempts to use it.
The Rails console likely loads different code paths or loads the library in a different order, which is why you don’t see the error there. However, for booting the full application, the explicit require is necessary.
By adding the require statement, you should resolve the uninitialized constant error.
Tycho is an AI agent, that grounds responses in various sources like documentation, code bases, live discussions, and relevant posts. Want to chat privately with Tycho?
No comments yet.
Answer by AstralMariner066 • 1 month ago
The concurrent-ruby version updated, that has a dependency with active support gem.
concurrent-ruby's 1.3.5 version just released few hours ago, but I think there is an issue on it.
Downgrading the concurrent-ruby's version to 1.3.4 in the gemfile will fix this.
No comments yet.
Answer by EclipseRanger679 • 1 month ago
concurrent-ruby v1.3.5 has removed the dependency on logger
https://github.com/ruby-concurrency/concurrent-ruby/commit/d7ce956dacd0b772273d39b8ed31a30cff7ecf38
Just block the gem into your gemfile to the previous version
RUBYgem 'concurrent-ruby', '1.3.4'
or update rails to 7.1, all Rails versions before are affected by this issue because they have a direct dependency on concurrent
No comments yet.
Answer by JovianStargazer774 • 1 month ago
Many of the answers have suggested pinning concurrent_ruby
to 1.3.4, but I believe that's misunderstanding the problem. There's no problem in concurrent-ruby
, this issue is actually in ActiveSupport 6 (and maybe 7.0), and concurrent-ruby
version prior to 1.3.5 masked the issue.
The issue in Rails was fixed in commit 0f5e7a66143.
The solution is to add require "logger"
(note that logger
is a core Ruby library) to your application/gem/test file prior to loading Rails (or ActiveSupport).
No comments yet.
Answer by OrbitalGuardian787 • 1 month ago
For me (MacOs Ventura 13.1) Adzap's answer worked but without the require "bootsnap/setup" since that wouldn't run.
Simply adding require "logger" to config/boot.rb did the trick.
No comments yet.
Answer by AsteroidWayfarer423 • 1 month ago
you need to update/downgrade ruby please follow these instructions as i had the same issue and fixed by this one
https://dev.to/luizgadao/easy-way-to-change-ruby-version-in-mac-m1-m2-and-m3-16hl
No comments yet.
Answer by NeptunianVoyager859 • 1 month ago
I’ve found a temporary workaround: add require "logger"
before require "rails"
at config/application.rb
.
However, I believe that locking the version of concurrent-ruby is also a solution.
No comments yet.
Answer by UranianSurveyor275 • 1 month ago
I have fixed the issue by doing the following in my project directory:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
echo >> /Users/zainishfaq/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/zainishfaq/.zprofile eval "$(/opt/homebrew/bin/brew shellenv)"
open .zshrc
Add the following in the zshrc file
BASHexport PATH=$HOME/development/flutter/bin:$PATH export PATH=$HOME/.gem/bin:$PATH # Add RVM to PATH for scripting. Make sure this is the last PATH variable change. export PATH="$PATH:$HOME/.rvm/bin" export PATH="/opt/homebrew/bin:$PATH"
rvm get stable
rvm install 3.1.2
No comments yet.
Answer by LunarScientist052 • 1 month ago
If anyone arrives here and is uncomfortable with locking the concurrent-ruby version, you can require logger and leave concurrent-ruby version unlocked. This is primarily an issue for older Rails 7.0 and 6.1.
In config/boot.rb
RUBYrequire "bundler/setup" # Set up gems listed in the Gemfile. require "logger" # Fix concurrent-ruby removing logger dependency which Rails itself does not have require "bootsnap/setup" # Speed up boot time by caching expensive operations.
No comments yet.
Answer by NovaPioneer512 • 1 month ago
This appears to have broken the cocoapods integration in our iOS project. As above, running
bundle add concurrent-ruby -v 1.3.4
in the project root resolved the issue.
This might cause issues down the road as cocoapods updates so keep an eye on that and remove this line if/ when that happens.
No comments yet.
No comments yet.