diff --git a/activesupport/lib/active_support/broadcast_logger.rb b/activesupport/lib/active_support/broadcast_logger.rb index 916c9c02b346..0225d17a9035 100644 --- a/activesupport/lib/active_support/broadcast_logger.rb +++ b/activesupport/lib/active_support/broadcast_logger.rb @@ -163,9 +163,19 @@ def initialize_copy(other) private def dispatch(method, *args, **kwargs, &block) - yield.tap do |result| - block = proc { result } - end if block_given? + if block_given? + # Maintain semantics that the first logger yields the block + # as normal, but subsequent loggers won't re-execute the block. + # Instead, the initial result is immediately returned. + called, result = false, nil + block = proc { |*args, **kwargs| + if called then result + else + called = true + result = yield(*args, **kwargs) + end + } + end @broadcasts.map { |logger| if logger.respond_to?(method)