diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/clean_logger.rb | 18 | ||||
-rw-r--r-- | activesupport/test/clean_logger_test.rb | 9 |
3 files changed, 26 insertions, 5 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 237a713255..4c01cf388c 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,3 +1,7 @@ +*SVN* + +* Set Logger.silencer = false to disable Logger#silence. Useful for debugging fixtures. + * Add title case method to String to do, e.g., 'action_web_service'.titlecase # => 'Action Web Service'. [Marcel Molina Jr.] *1.2.1* (October 19th, 2005) diff --git a/activesupport/lib/active_support/clean_logger.rb b/activesupport/lib/active_support/clean_logger.rb index 330dbb2e46..89dfae8f2f 100644 --- a/activesupport/lib/active_support/clean_logger.rb +++ b/activesupport/lib/active_support/clean_logger.rb @@ -1,12 +1,22 @@ require 'logger' +require File.dirname(__FILE__) + '/class_attribute_accessors' class Logger #:nodoc: + cattr_accessor :silencer + self.silencer = true + # Silences the logger for the duration of the block. def silence(temporary_level = Logger::ERROR) - old_logger_level, self.level = level, temporary_level - yield self - ensure - self.level = old_logger_level + if silencer + begin + old_logger_level, self.level = level, temporary_level + yield self + ensure + self.level = old_logger_level + end + else + yield self + end end private diff --git a/activesupport/test/clean_logger_test.rb b/activesupport/test/clean_logger_test.rb index c5ddc713c2..2ff3fd6832 100644 --- a/activesupport/test/clean_logger_test.rb +++ b/activesupport/test/clean_logger_test.rb @@ -32,7 +32,14 @@ class CleanLoggerTest < Test::Unit::TestCase logger.fatal 'fatal' end - assert_equal "error\nfatal\nerror\nfatal\n", @out.string + # Silencer off. + Logger.silencer = false + @logger.silence do |logger| + logger.warn 'unsilenced' + end + Logger.silencer = true + + assert_equal "error\nfatal\nerror\nfatal\nunsilenced\n", @out.string end end |