mirror of
https://github.com/github/rails.git
synced 2026-01-29 16:28:09 -05:00
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
This commit is contained in:
@@ -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 @@ 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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user