2008-01-05 13:31:04 +00:00
|
|
|
require 'abstract_unit'
|
2005-10-13 19:05:32 +00:00
|
|
|
require 'stringio'
|
2011-12-20 02:41:37 +00:00
|
|
|
require 'active_support/logger'
|
2005-10-13 19:05:32 +00:00
|
|
|
|
|
|
|
class CleanLoggerTest < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
@out = StringIO.new
|
2011-12-20 02:41:37 +00:00
|
|
|
@logger = ActiveSupport::Logger.new(@out)
|
2005-10-13 19:05:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_format_message
|
|
|
|
@logger.error 'error'
|
|
|
|
assert_equal "error\n", @out.string
|
|
|
|
end
|
|
|
|
|
2007-02-25 00:07:54 +00:00
|
|
|
def test_datetime_format
|
|
|
|
@logger.formatter = Logger::Formatter.new
|
2011-12-20 02:41:37 +00:00
|
|
|
@logger.formatter.datetime_format = "%Y-%m-%d"
|
2007-02-25 00:07:54 +00:00
|
|
|
@logger.debug 'debug'
|
2011-12-20 02:41:37 +00:00
|
|
|
assert_equal "%Y-%m-%d", @logger.formatter.datetime_format
|
2007-02-25 00:07:54 +00:00
|
|
|
assert_match(/D, \[\d\d\d\d-\d\d-\d\d#\d+\] DEBUG -- : debug/, @out.string)
|
|
|
|
end
|
2010-08-14 05:13:00 +00:00
|
|
|
|
2007-09-22 18:25:30 +00:00
|
|
|
def test_nonstring_formatting
|
|
|
|
an_object = [1, 2, 3, 4, 5]
|
|
|
|
@logger.debug an_object
|
|
|
|
assert_equal("#{an_object.inspect}\n", @out.string)
|
|
|
|
end
|
2005-10-13 19:05:32 +00:00
|
|
|
end
|