Fix `BroadcastLogger#dup` so that it duplicates the logger's `broadcasts`.

This commit is contained in:
Andrew Novoselac 2023-10-20 10:26:03 -04:00
parent 7de3400f90
commit c14b98c28a
3 changed files with 24 additions and 0 deletions

View File

@ -1,3 +1,7 @@
* Fix `BroadcastLogger#dup` so that it duplicates the logger's `broadcasts`.
*Andrew Novoselac*
* Fix issue where `bootstrap.rb` overwrites the `level` of a `BroadcastLogger`'s `broadcasts`.
*Andrew Novoselac*

View File

@ -218,6 +218,14 @@ module ActiveSupport
dispatch { |logger| logger.fatal! }
end
def initialize_copy(other)
@broadcasts = []
@progname = other.progname.dup
@formatter = other.formatter.dup
broadcast_to(*other.broadcasts.map(&:dup))
end
private
def dispatch(&block)
@broadcasts.each { |logger| block.call(logger) }

View File

@ -290,6 +290,18 @@ module ActiveSupport
assert(logger.qux(param: "foo"))
end
test "#dup duplicates the broadcasts" do
logger = CustomLogger.new
logger.level = ::Logger::WARN
broadcast_logger = BroadcastLogger.new(logger)
duplicate = broadcast_logger.dup
assert_equal ::Logger::WARN, duplicate.broadcasts.sole.level
assert_not_same logger, duplicate.broadcasts.sole
assert_same logger, broadcast_logger.broadcasts.sole
end
class CustomLogger
attr_reader :adds, :closed, :chevrons
attr_accessor :level, :progname, :formatter, :local_level