{"id":13454,"date":"2025-09-11T07:51:22","date_gmt":"2025-09-11T07:51:22","guid":{"rendered":"https:\/\/www.bacancytechnology.com\/qanda\/?p=13454"},"modified":"2025-09-11T07:51:22","modified_gmt":"2025-09-11T07:51:22","slug":"activesupport-loggerthreadsafelevel-logger-nameerror","status":"publish","type":"post","link":"https:\/\/www.bacancytechnology.com\/qanda\/ruby-on-rails\/activesupport-loggerthreadsafelevel-logger-nameerror","title":{"rendered":"Uninitialized Constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)"},"content":{"rendered":"<h2>Problem Statement<\/h2>\n<p>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:<br \/>\nuninitialized constant ActiveSupport::LoggerThreadSafeLevel::Logger (NameError)<\/p>\n<p>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.<\/p>\n<h2>Answer<\/h2>\n<p>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.<\/p>\n<p>In earlier versions, this worked fine because one of Rails\u2019 dependencies (concurrent-ruby) automatically loaded Logger.<\/p>\n<p>But from version 1.3.5, concurrent-ruby stopped loading Logger by default. So now, if Logger isn\u2019t manually required, Rails throws this error.<\/p>\n<h2>Solutions<\/h2>\n<h3>1. Manually Require the logger Library<\/h3>\n<p>Add the following line to the top of your config\/application.rb:<\/p>\n<p><code>require 'logger'<\/code><br \/>\nOr add it to config\/boot.rb before Rails is loaded:<br \/>\n<code>require 'bundler\/setup'<br \/>\nrequire 'logger'<\/code><br \/>\nWhy this works: It explicitly loads the Ruby standard Logger class before Rails references it.<\/p>\n<h3>2. Pin concurrent-ruby to Version 1.3.4<\/h3>\n<p>In your Gemfile:<br \/>\n<code>gem 'concurrent-ruby', '1.3.4'<\/code><br \/>\nThen run:<br \/>\n<code>bundle install<\/code><br \/>\nWhy this works: concurrent-ruby v1.3.4 still autoloads Logger, which avoids the uninitialized constant error.<\/p>\n<h3>3. Upgrade Rails to 7.1+ (Long-Term Fix)<\/h3>\n<p>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.<\/p>\n<p>Why this works: The new version handles logger loading without relying on indirect dependencies.<\/p>\n<div class=\"qanda-read-box\"><div class=\"bg-light read-more-icon\"><img decoding=\"async\" src=\"https:\/\/assets.bacancytechnology.com\/qanda\/wp-content\/uploads\/2025\/04\/24061434\/read-txt.png\" alt=\"Also Read\"><p><\/p><h3>Also Read:<\/h3><a href=\"https:\/\/www.bacancytechnology.com\/blog\/design-patterns-in-ruby-on-rails\" target=\"_blank\">Design Patterns in Rails<\/a><\/div><\/div>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":13455,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[11],"tags":[],"class_list":["post-13454","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ruby-on-rails"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/13454"}],"collection":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/comments?post=13454"}],"version-history":[{"count":1,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/13454\/revisions"}],"predecessor-version":[{"id":13456,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/posts\/13454\/revisions\/13456"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media\/13455"}],"wp:attachment":[{"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/media?parent=13454"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/categories?post=13454"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bacancytechnology.com\/qanda\/wp-json\/wp\/v2\/tags?post=13454"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}