mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Revert "Add Logger option to disable message broadcasts"
This reverts related commits due to #22917.
This commit is contained in:
parent
b7b508aa79
commit
9dcb1b9b07
3 changed files with 22 additions and 45 deletions
|
@ -1,3 +1,4 @@
|
|||
require 'active_support/core_ext/module/attribute_accessors'
|
||||
require 'active_support/logger_silence'
|
||||
require 'logger'
|
||||
|
||||
|
@ -5,26 +6,16 @@ module ActiveSupport
|
|||
class Logger < ::Logger
|
||||
include LoggerSilence
|
||||
|
||||
# If +true+, will broadcast all messages sent to this logger to any
|
||||
# logger linked to this one via +broadcast+.
|
||||
#
|
||||
# If +false+, the logger will still forward calls to +close+, +progname=+,
|
||||
# +formatter=+ and +level+ to any linked loggers, but no calls to +add+ or
|
||||
# +<<+.
|
||||
#
|
||||
# Defaults to +true+.
|
||||
attr_accessor :broadcast_messages # :nodoc:
|
||||
|
||||
# Broadcasts logs to multiple loggers.
|
||||
def self.broadcast(logger) # :nodoc:
|
||||
Module.new do
|
||||
define_method(:add) do |*args, &block|
|
||||
logger.add(*args, &block) if broadcast_messages
|
||||
logger.add(*args, &block)
|
||||
super(*args, &block)
|
||||
end
|
||||
|
||||
define_method(:<<) do |x|
|
||||
logger << x if broadcast_messages
|
||||
logger << x
|
||||
super(x)
|
||||
end
|
||||
|
||||
|
|
|
@ -42,4 +42,4 @@ module LoggerSilence
|
|||
yield self
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -2,69 +2,56 @@ require 'abstract_unit'
|
|||
|
||||
module ActiveSupport
|
||||
class BroadcastLoggerTest < TestCase
|
||||
attr_reader :logger, :receiving_logger
|
||||
attr_reader :logger, :log1, :log2
|
||||
def setup
|
||||
@logger = FakeLogger.new
|
||||
@receiving_logger = FakeLogger.new
|
||||
@logger.extend Logger.broadcast @receiving_logger
|
||||
@log1 = FakeLogger.new
|
||||
@log2 = FakeLogger.new
|
||||
@log1.extend Logger.broadcast @log2
|
||||
@logger = @log1
|
||||
end
|
||||
|
||||
def test_debug
|
||||
logger.debug "foo"
|
||||
assert_equal 'foo', logger.adds.first[2]
|
||||
assert_equal 'foo', receiving_logger.adds.first[2]
|
||||
end
|
||||
|
||||
def test_debug_without_message_broadcasts
|
||||
logger.broadcast_messages = false
|
||||
logger.debug "foo"
|
||||
assert_equal 'foo', logger.adds.first[2]
|
||||
assert_equal [], receiving_logger.adds
|
||||
assert_equal 'foo', log1.adds.first[2]
|
||||
assert_equal 'foo', log2.adds.first[2]
|
||||
end
|
||||
|
||||
def test_close
|
||||
logger.close
|
||||
assert logger.closed, 'should be closed'
|
||||
assert receiving_logger.closed, 'should be closed'
|
||||
assert log1.closed, 'should be closed'
|
||||
assert log2.closed, 'should be closed'
|
||||
end
|
||||
|
||||
def test_chevrons
|
||||
logger << "foo"
|
||||
assert_equal %w{ foo }, logger.chevrons
|
||||
assert_equal %w{ foo }, receiving_logger.chevrons
|
||||
end
|
||||
|
||||
def test_chevrons_without_message_broadcasts
|
||||
logger.broadcast_messages = false
|
||||
logger << "foo"
|
||||
assert_equal %w{ foo }, logger.chevrons
|
||||
assert_equal [], receiving_logger.chevrons
|
||||
assert_equal %w{ foo }, log1.chevrons
|
||||
assert_equal %w{ foo }, log2.chevrons
|
||||
end
|
||||
|
||||
def test_level
|
||||
assert_nil logger.level
|
||||
logger.level = 10
|
||||
assert_equal 10, logger.level
|
||||
assert_equal 10, receiving_logger.level
|
||||
assert_equal 10, log1.level
|
||||
assert_equal 10, log2.level
|
||||
end
|
||||
|
||||
def test_progname
|
||||
assert_nil logger.progname
|
||||
logger.progname = 10
|
||||
assert_equal 10, logger.progname
|
||||
assert_equal 10, receiving_logger.progname
|
||||
assert_equal 10, log1.progname
|
||||
assert_equal 10, log2.progname
|
||||
end
|
||||
|
||||
def test_formatter
|
||||
assert_nil logger.formatter
|
||||
logger.formatter = 10
|
||||
assert_equal 10, logger.formatter
|
||||
assert_equal 10, receiving_logger.formatter
|
||||
assert_equal 10, log1.formatter
|
||||
assert_equal 10, log2.formatter
|
||||
end
|
||||
|
||||
class FakeLogger
|
||||
attr_reader :adds, :closed, :chevrons
|
||||
attr_accessor :level, :progname, :formatter, :broadcast_messages
|
||||
attr_accessor :level, :progname, :formatter
|
||||
|
||||
def initialize
|
||||
@adds = []
|
||||
|
@ -73,7 +60,6 @@ module ActiveSupport
|
|||
@level = nil
|
||||
@progname = nil
|
||||
@formatter = nil
|
||||
@broadcast_messages = true
|
||||
end
|
||||
|
||||
def debug msg, &block
|
||||
|
|
Loading…
Reference in a new issue