Fix GH #4760. A Block was not evaluated.

This commit is contained in:
kennyj
2012-01-31 21:26:17 +09:00
parent b2955edcea
commit 91700bfc2d
2 changed files with 11 additions and 2 deletions

View File

@@ -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

View File

@@ -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