Permalink
Browse files

BufferedLogger#add converts the message to a string. Closes #9724.

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 ccb87e2f6984d64bc463bfd75ec78dac75a8a98c
View
@@ -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]
@@ -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
@@ -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
@@ -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

0 comments on commit ccb87e2

Please sign in to comment.