Skip to content

Commit

Permalink
Fix GH rails#4760. A Block was not evaluated.
Browse files Browse the repository at this point in the history
  • Loading branch information
kennyj committed Jan 31, 2012
1 parent b2955ed commit 91700bf
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
5 changes: 3 additions & 2 deletions activesupport/lib/active_support/tagged_logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,14 @@ def silence(temporary_level = Logger::ERROR, &block)
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
Expand Down
8 changes: 8 additions & 0 deletions activesupport/test/tagged_logging_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,12 @@ def flush(*)
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

2 comments on commit 91700bf

@mledom
Copy link

@mledom mledom commented on 91700bf Jan 31, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That seems to be working for me. Great job, thanks!!!

@kennyj
Copy link
Owner Author

@kennyj kennyj commented on 91700bf Jan 31, 2012

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks !
I'll send pull request.

Please sign in to comment.