diff options
author | José Valim <jose.valim@plataformatec.com.br> | 2012-01-31 07:09:56 -0800 |
---|---|---|
committer | José Valim <jose.valim@plataformatec.com.br> | 2012-01-31 07:09:56 -0800 |
commit | bd93ba5b16ae7a150ea0da282fc1277677c13f49 (patch) | |
tree | d6877b693bb88e86782a3adca5e9771b47f75c01 /activesupport | |
parent | 85c724d59e46953c52fb457411597fbab90f3a4a (diff) | |
parent | 91700bfc2dce8a9c473087d206a3498eeecb1ca0 (diff) | |
download | rails-bd93ba5b16ae7a150ea0da282fc1277677c13f49.tar.gz rails-bd93ba5b16ae7a150ea0da282fc1277677c13f49.tar.bz2 rails-bd93ba5b16ae7a150ea0da282fc1277677c13f49.zip |
Merge pull request #4793 from kennyj/fix_4760
[3-2-stable] Fix GH #4760. A Block was not evaluated.
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/tagged_logging.rb | 5 | ||||
-rw-r--r-- | activesupport/test/tagged_logging_test.rb | 8 |
2 files changed, 11 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/tagged_logging.rb b/activesupport/lib/active_support/tagged_logging.rb index d71215b447..6af87e85e6 100644 --- a/activesupport/lib/active_support/tagged_logging.rb +++ b/activesupport/lib/active_support/tagged_logging.rb @@ -33,13 +33,14 @@ module ActiveSupport deprecate :silence def add(severity, message = nil, progname = nil, &block) - @logger.add(severity, "#{tags_text}#{message}", progname, &block) + message = (block_given? ? block.call : progname) if message.nil? + @logger.add(severity, "#{tags_text}#{message}", progname) end %w( fatal error warn info debug unknown ).each do |severity| eval <<-EOM, nil, __FILE__, __LINE__ + 1 def #{severity}(progname = nil, &block) - add(Logger::#{severity.upcase}, progname, &block) + add(Logger::#{severity.upcase}, nil, progname, &block) end EOM end diff --git a/activesupport/test/tagged_logging_test.rb b/activesupport/test/tagged_logging_test.rb index 7ecab33a9a..c838c073e6 100644 --- a/activesupport/test/tagged_logging_test.rb +++ b/activesupport/test/tagged_logging_test.rb @@ -70,4 +70,12 @@ class TaggedLoggingTest < ActiveSupport::TestCase assert_nothing_raised { @logger.silence {} } end end + + test "calls block" do + @logger.tagged("BCX") do + @logger.info { "Funky town" } + end + assert_equal "[BCX] Funky town\n", @output.string + end + end |