diff options
-rw-r--r-- | activesupport/CHANGELOG | 2 | ||||
-rw-r--r-- | activesupport/lib/active_support/buffered_logger.rb | 4 | ||||
-rw-r--r-- | activesupport/test/buffered_logger_test.rb | 6 |
3 files changed, 11 insertions, 1 deletions
diff --git a/activesupport/CHANGELOG b/activesupport/CHANGELOG index ea31261c95..737e60cda8 100644 --- a/activesupport/CHANGELOG +++ b/activesupport/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* BufferedLogger#add doesn't modify the message argument. #9702 [eigentone] + * 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] * Object#instance_exec produces fewer garbage methods. [Mauricio Fernandez] diff --git a/activesupport/lib/active_support/buffered_logger.rb b/activesupport/lib/active_support/buffered_logger.rb index c646b43d96..6025e1a6d0 100644 --- a/activesupport/lib/active_support/buffered_logger.rb +++ b/activesupport/lib/active_support/buffered_logger.rb @@ -52,7 +52,9 @@ module ActiveSupport def add(severity, message = nil, progname = nil, &block) return if @level > severity message = message || (block && block.call) || progname - message << "\n" unless message[-1] == ?\n + # If a newline is nessesary then create a new message end with a new line. + # Ensures that the original message is not mutated. + message = "#{message}\n" unless message[-1] == ?\n @buffer << message flush if auto_flushing message diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb index 7d55715084..f15b4c3a37 100644 --- a/activesupport/test/buffered_logger_test.rb +++ b/activesupport/test/buffered_logger_test.rb @@ -38,4 +38,10 @@ class BufferedLoggerTest < Test::Unit::TestCase @logger.add(Logger::DEBUG) {evaluated = true} assert evaluated == false end + + def test_should_not_mutate_message + message_copy = @message.dup + @logger.info @message + assert_equal message_copy, @message + end end |