mirror of https://github.com/rails/rails
Fix `BroadcastLogger#dup` so that it duplicates the logger's `broadcasts`.
This commit is contained in:
parent
7de3400f90
commit
c14b98c28a
|
@ -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*
|
||||
|
|
|
@ -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) }
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue