From d6c4f4a38b2dc83dd6af534f39e7c348cc58823d Mon Sep 17 00:00:00 2001 From: Iuri G <289754+iuri-gg@users.noreply.github.com> Date: Sun, 15 Oct 2023 12:25:04 -0500 Subject: [PATCH] Fix broadcast logging in rails 7.1+ --- CHANGELOG.md | 2 ++ lib/anycable/rails/railtie.rb | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e3bc81..7a212b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,8 @@ - Add `batch_broadcasts` option to automatically batch broadcasts for code wrapped in Rails executor. ([@palkan][]) +- Fix broadcast logging in Rails 7.1. ([@iuri-gg][]) + ## 1.4.1 (2023-09-27) - Fix compatibility with Rails 7.1. ([@palkan][]) diff --git a/lib/anycable/rails/railtie.rb b/lib/anycable/rails/railtie.rb index bb969ef..613c489 100644 --- a/lib/anycable/rails/railtie.rb +++ b/lib/anycable/rails/railtie.rb @@ -31,8 +31,8 @@ class Railtie < ::Rails::Railtie # :nodoc: console.level = ::Rails.logger.level if ::Rails.logger.respond_to?(:level) # Rails 7.1+ - if defined?(ActiveSupport::BroadcastLogger) - AnyCable.logger = ActiveSupport::BroadcastLogger.new(AnyCable.logger, console) + if AnyCable.logger.respond_to?(:broadcast_to) + AnyCable.logger.broadcast_to(console) else AnyCable.logger.extend(ActiveSupport::Logger.broadcast(console)) end