Skip to content

Commit

Permalink
BufferedLogger#add converts the message to a string. Closes #9724.
Browse files Browse the repository at this point in the history
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7664 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Sep 28, 2007
1 parent bbdb4e5 commit ccb87e2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion activesupport/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

* Backport Object#instance_variable_defined? for Ruby < 1.8.6. [Jeremy Kemper]

* BufferedLogger#add doesn't modify the message argument. #9702 [eigentone]
* BufferedLogger#add converts the message to a string. #9702, #9724 [eigentone, DrMark, tomafro]

* Added ActiveSupport::BufferedLogger as a duck-typing alternative (albeit with no formatter) to the Ruby Logger, which provides a very nice speed bump (inspired by Ezra's buffered logger) [DHH]

Expand Down
2 changes: 1 addition & 1 deletion activesupport/lib/active_support/buffered_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def initialize(log, level = DEBUG)

def add(severity, message = nil, progname = nil, &block)
return if @level > severity
message = message || (block && block.call) || progname
message = (message || (block && block.call) || progname).to_s
# If a newline is necessary then create a new message ending with a newline.
# Ensures that the original message is not mutated.
message = "#{message}\n" unless message[-1] == ?\n
Expand Down
13 changes: 13 additions & 0 deletions activesupport/test/buffered_logger_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class BufferedLoggerTest < Test::Unit::TestCase
def setup
@message = "A debug message"
@integer_message = 12345
@output = StringIO.new
@logger = ActiveSupport::BufferedLogger.new(@output)
end
Expand Down Expand Up @@ -32,6 +33,18 @@ def test_should_add_message_passed_as_block_when_using_shortcut
assert @output.string.include?(@message)
end

def test_should_convert_message_to_string
@logger.level = Logger::INFO
@logger.info @integer_message
assert @output.string.include?(@integer_message.to_s)
end

def test_should_convert_message_to_string_when_passed_in_block
@logger.level = Logger::INFO
@logger.info {@integer_message}
assert @output.string.include?(@integer_message.to_s)
end

def test_should_not_evaluate_block_if_message_wont_be_logged
@logger.level = Logger::INFO
evaluated = false
Expand Down

0 comments on commit ccb87e2

Please sign in to comment.