Clone to keep extended Logger methods for tagged logger
`#dup` resets the extended Logger methods that could come from enabling broadcasting. That would mean if we create a tagged logger from a Logger with broadcasting enabled (usually to stdout), the new tagged logger will not perform broadcasting.
This commit is contained in:
parent
9b6008924d
commit
70af536b5d
|
@ -79,7 +79,7 @@ module ActiveSupport
|
|||
end
|
||||
|
||||
def self.new(logger)
|
||||
logger = logger.dup
|
||||
logger = logger.clone
|
||||
|
||||
if logger.formatter
|
||||
logger.formatter = logger.formatter.dup
|
||||
|
|
|
@ -214,4 +214,16 @@ class TaggedLoggingWithoutBlockTest < ActiveSupport::TestCase
|
|||
|
||||
assert_equal "[BCX] [Jason] Funky time\n[BCX] Junky time!\n", @output.string
|
||||
end
|
||||
|
||||
test "keeps broadcasting functionality" do
|
||||
broadcast_output = StringIO.new
|
||||
broadcast_logger = ActiveSupport::TaggedLogging.new(Logger.new(broadcast_output))
|
||||
@logger.extend(ActiveSupport::Logger.broadcast(broadcast_logger))
|
||||
|
||||
tagged_logger = @logger.tagged("OMG")
|
||||
tagged_logger.info "Broadcasting..."
|
||||
|
||||
assert_equal "[OMG] Broadcasting...\n", @output.string
|
||||
assert_equal "[OMG] Broadcasting...\n", broadcast_output.string
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue