aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorGuo Xiang Tan <tgx_world@hotmail.com>2016-10-24 18:26:13 +0800
committerGuo Xiang Tan <tgx_world@hotmail.com>2016-10-24 18:26:13 +0800
commit308e84e982b940983b4b3d5b41b0b3ac11fbae40 (patch)
tree89d58e3f8e03555cf0474d62c5fcad7cc8b881fd /activesupport
parenta0d0648efb5faa5d8d94a090e8b6ff498a7a9475 (diff)
downloadrails-308e84e982b940983b4b3d5b41b0b3ac11fbae40.tar.gz
rails-308e84e982b940983b4b3d5b41b0b3ac11fbae40.tar.bz2
rails-308e84e982b940983b4b3d5b41b0b3ac11fbae40.zip
`Broadcast#silence` breaks custom loggers that does not include `LoggerSilence`.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/logger.rb4
-rw-r--r--activesupport/test/broadcast_logger_test.rb22
2 files changed, 21 insertions, 5 deletions
diff --git a/activesupport/lib/active_support/logger.rb b/activesupport/lib/active_support/logger.rb
index 3ba6461b57..ea09d7d2df 100644
--- a/activesupport/lib/active_support/logger.rb
+++ b/activesupport/lib/active_support/logger.rb
@@ -59,14 +59,14 @@ module ActiveSupport
define_method(:silence) do |level = Logger::ERROR, &block|
if logger.respond_to?(:silence)
logger.silence(level) do
- if respond_to?(:silence)
+ if defined?(super)
super(level, &block)
else
block.call(self)
end
end
else
- if respond_to?(:silence)
+ if defined?(super)
super(level, &block)
else
block.call(self)
diff --git a/activesupport/test/broadcast_logger_test.rb b/activesupport/test/broadcast_logger_test.rb
index 4b74f1313e..aaa657ce13 100644
--- a/activesupport/test/broadcast_logger_test.rb
+++ b/activesupport/test/broadcast_logger_test.rb
@@ -69,6 +69,20 @@ module ActiveSupport
assert_equal ::Logger::FATAL, log2.local_level
end
+ test "#silence does not break custom loggers" do
+ new_logger = FakeLogger.new
+ custom_logger = CustomLogger.new
+ custom_logger.extend(Logger.broadcast(new_logger))
+
+ custom_logger.silence do
+ custom_logger.error "from error"
+ custom_logger.unknown "from unknown"
+ end
+
+ assert_equal [[::Logger::ERROR, "from error", nil], [::Logger::UNKNOWN, "from unknown", nil]], custom_logger.adds
+ assert_equal [[::Logger::ERROR, "from error", nil], [::Logger::UNKNOWN, "from unknown", nil]], new_logger.adds
+ end
+
test "#silence silences all loggers below the default level of ERROR" do
logger.silence do
logger.debug "test"
@@ -98,9 +112,7 @@ module ActiveSupport
assert_equal [[::Logger::FATAL, "seen", nil]], log2.adds
end
- class FakeLogger
- include LoggerSilence
-
+ class CustomLogger
attr_reader :adds, :closed, :chevrons
attr_accessor :level, :progname, :formatter, :local_level
@@ -150,5 +162,9 @@ module ActiveSupport
@closed = true
end
end
+
+ class FakeLogger < CustomLogger
+ include LoggerSilence
+ end
end
end