0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

ActiveSupport::LoggerThreadSafeLevel::Loggerの対処を行う

Last updated at Posted at 2025-03-29

Railsで ActiveSupport::LoggerThreadSafeLevel::Logger エラーが出る原因と対処法

はじめに

こんにちは。
課題を行うため、アプリを開発しようとしたのですが、エラー続出で戸惑ってしまいました。
アウトプットのために、まとめておきます。

開発環境

  • OS: macOS Sonoma 14.6.1
  • Ruby: 3.1.4(rbenv使用)
  • Rails: 6.1.7.6
  • Bundler: 2.6.6
  • PostgreSQL: 14
  • Node.js: 18.x(webpacker用)
  • Yarn: 1.x(webpacker用)
  • rbenv: 使用(Homebrew経由でインストール)

発生したエラー

Rails アプリ作成や起動時に、以下のようなエラーが発生しました。

  • bundle exec rails new の直後
  • bin/rails s をしたとき
  • Ruby 2.7〜3.1 環境でも確認

原因

Rails の内部ライブラリ activesupportLogger::Severity を参照。

しかし、concurrent-ruby gem の バージョン 1.3.5 以降Logger 関連の処理に変更が入り、 Rails 側から参照できなくなり、このエラーが発生。

対処できた方法

concurrent-ruby1.3.4 に固定

修正手順

Gemfile に以下を追加 or 修正

gem 'concurrent-ruby', '1.3.4'

bundle update でバージョンをダウングレード

bundle update concurrent-ruby

その後、依存関係を再インストール

bundle install

Rails アプリを作成 or 起動。

# アプリ作成
bundle exec rails new my_app --database=postgresql

# すでに作ってある場合はサーバー起動
rails s

なぜこのエラーが起きるのか?

様々な記事を参照したところ、
Rails 6.x は Logger::Severity を暗黙的に使用。
concurrent-ruby 1.3.5 でその部分の内部実装が変更・削除されたことで、
Rails 側が期待する Logger 定数が存在しなくなり、エラーが発生するようになったとのこと。

まとめ

  1. ActiveSupport::LoggerThreadSafeLevel::Logger のエラーは concurrent-ruby のアップデートが原因
  2. concurrent-ruby を 1.3.4 に回避できる可能性がある

おわりに

Rails のエラーに振り回されましたが、どうにか無事解決できました。
初学者のため、間違えていたらすいません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?