Skip to content

Commit d0fd880

Browse files
authored
Merge pull request rails#49462 from Edouard-chin/ec-broadcast-prevent
Handle case when `config.logger` is already a BroadcastLogger:
2 parents d24bbcd + c577cc9 commit d0fd880

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

railties/lib/rails/application/bootstrap.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ module Bootstrap
5656
end
5757
Rails.logger.level = ActiveSupport::Logger.const_get(config.log_level.to_s.upcase)
5858

59-
broadcast_logger = ActiveSupport::BroadcastLogger.new(Rails.logger)
60-
broadcast_logger.formatter = Rails.logger.formatter
61-
Rails.logger = broadcast_logger
59+
unless Rails.logger.is_a?(ActiveSupport::BroadcastLogger)
60+
broadcast_logger = ActiveSupport::BroadcastLogger.new(Rails.logger)
61+
broadcast_logger.formatter = Rails.logger.formatter
62+
Rails.logger = broadcast_logger
63+
end
6264

6365
unless config.consider_all_requests_local
6466
Rails.error.logger = Rails.logger

railties/test/application/configuration_test.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1893,6 +1893,26 @@ def index
18931893
assert_equal Logger::DEBUG, Rails.logger.level
18941894
end
18951895

1896+
test "config.logger when logger is already a Broadcast Logger" do
1897+
logger = ActiveSupport::BroadcastLogger.new
1898+
1899+
make_basic_app do |application|
1900+
application.config.logger = logger
1901+
end
1902+
assert_same(logger, Rails.logger)
1903+
end
1904+
1905+
test "config.logger when logger is not a Broadcast Logger" do
1906+
logger = Logger.new(STDOUT)
1907+
1908+
make_basic_app do |application|
1909+
application.config.logger = logger
1910+
end
1911+
1912+
assert_instance_of(ActiveSupport::BroadcastLogger, Rails.logger)
1913+
assert_includes(Rails.logger.broadcasts, logger)
1914+
end
1915+
18961916
test "respond_to? accepts include_private" do
18971917
make_basic_app
18981918

0 commit comments

Comments
 (0)