Skip to content

Commit a054307

Browse files
ElMassimorafaelfranca
authored andcommitted
Improve compatibility between Logger and ActiveSupport::BroadcastLogger
The usage of `dispatch` in all logging methods causes common usages such as `logger.info` to return an array of loggers, making it unsafe for an application to upgrade to Rails 7.1. Returning `nil` is more efficient, and is the default behavior when using `Logger`.
1 parent b9f814a commit a054307

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

activesupport/lib/active_support/broadcast_logger.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def initialize_copy(other)
229229
private
230230
def dispatch(&block)
231231
@broadcasts.each { |logger| block.call(logger) }
232+
true
232233
end
233234

234235
def method_missing(name, ...)

activesupport/test/broadcast_logger_test.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,11 @@ def info(msg, &block)
302302
assert_same logger, broadcast_logger.broadcasts.sole
303303
end
304304

305+
test "logging has no return value" do
306+
assert_equal true, @logger.info("Hello")
307+
assert_equal true, @logger.error("Hello")
308+
end
309+
305310
class CustomLogger
306311
attr_reader :adds, :closed, :chevrons
307312
attr_accessor :level, :progname, :formatter, :local_level

0 commit comments

Comments
 (0)