提交 6f06ac6e 编写于 作者: J Jeremy Kemper

BufferedLogger#add doesn't modify the message argument. Closes #9702.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7643 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
上级 1c68394b
*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]
......
......@@ -52,7 +52,9 @@ def initialize(log, level = DEBUG)
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
......
......@@ -38,4 +38,10 @@ def test_should_not_evaluate_block_if_message_wont_be_logged
@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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册