diff options
author | Piotr Jakubowski <piotrj@gmail.com> | 2016-02-11 21:00:51 +0100 |
---|---|---|
committer | Piotr Jakubowski <piotrj@gmail.com> | 2016-02-11 21:00:51 +0100 |
commit | 2518bda97cbbcb33dc9a92e70d5b01c09e64d12d (patch) | |
tree | ba6404706f942b8896614d0172854c5cb348fc90 /activesupport/test/logger_test.rb | |
parent | 8a84f1c047ebb59dec7a7ece9355da9c7b0ae6b7 (diff) | |
download | rails-2518bda97cbbcb33dc9a92e70d5b01c09e64d12d.tar.gz rails-2518bda97cbbcb33dc9a92e70d5b01c09e64d12d.tar.bz2 rails-2518bda97cbbcb33dc9a92e70d5b01c09e64d12d.zip |
Fix logger silencing for broadcasted loggers
Fix #23609
Commit 629efb6 introduced thread safety to logger silencing but it
didn't take into account the fact that the logger can be extended with
broadcasting to other logger.
This commit introduces local_level to broadcasting Module which enables
broadcasted loggers to be properly silenced.
Diffstat (limited to 'activesupport/test/logger_test.rb')
-rw-r--r-- | activesupport/test/logger_test.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/activesupport/test/logger_test.rb b/activesupport/test/logger_test.rb index 317e09b7f2..5a91420f1e 100644 --- a/activesupport/test/logger_test.rb +++ b/activesupport/test/logger_test.rb @@ -141,6 +141,50 @@ class LoggerTest < ActiveSupport::TestCase assert @output.string.include?("THIS IS HERE") end + def test_logger_silencing_works_for_broadcast + another_output = StringIO.new + another_logger = Logger.new(another_output) + + @logger.extend Logger.broadcast(another_logger) + + @logger.debug "CORRECT DEBUG" + @logger.silence do + @logger.debug "FAILURE" + @logger.error "CORRECT ERROR" + end + + assert @output.string.include?("CORRECT DEBUG") + assert @output.string.include?("CORRECT ERROR") + assert_not @output.string.include?("FAILURE") + + assert another_output.string.include?("CORRECT DEBUG") + assert another_output.string.include?("CORRECT ERROR") + assert_not another_output.string.include?("FAILURE") + end + + def test_broadcast_silencing_does_not_break_plain_ruby_logger + another_output = StringIO.new + another_logger = ::Logger.new(another_output) + + @logger.extend Logger.broadcast(another_logger) + + @logger.debug "CORRECT DEBUG" + @logger.silence do + @logger.debug "FAILURE" + @logger.error "CORRECT ERROR" + end + + assert @output.string.include?("CORRECT DEBUG") + assert @output.string.include?("CORRECT ERROR") + assert_not @output.string.include?("FAILURE") + + assert another_output.string.include?("CORRECT DEBUG") + assert another_output.string.include?("CORRECT ERROR") + assert another_output.string.include?("FAILURE") + # We can't silence plain ruby Logger cause with thread safety + # but at least we don't break it + end + def test_logger_level_per_object_thread_safety logger1 = Logger.new(StringIO.new) logger2 = Logger.new(StringIO.new) |