diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/buffered_logger.rb | 2 | ||||
-rw-r--r-- | activesupport/test/buffered_logger_test.rb | 13 |
3 files changed, 15 insertions, 2 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index 1d94b13319..70fffe1775 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -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] diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb index a3715e2e84..9b840091a5 100644 --- a/activesupport/lib/active_support/buffered_logger.rb +++ b/activesupport/lib/active_support/buffered_logger.rb @@ -51,7 +51,7 @@ module ActiveSupport 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 diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb index f15b4c3a37..9a78ee3694 100644 --- a/activesupport/test/buffered_logger_test.rb +++ b/activesupport/test/buffered_logger_test.rb @@ -4,6 +4,7 @@ require 'stringio' 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 @@ class BufferedLoggerTest < Test::Unit::TestCase 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 |