2017-07-09 08:06:36 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:39:13 -04:00
|
|
|
|
2018-09-29 20:50:43 -04:00
|
|
|
require_relative "abstract_unit"
|
2016-08-06 12:03:25 -04:00
|
|
|
require "stringio"
|
|
|
|
require "active_support/logger"
|
2005-10-13 15:05:32 -04:00
|
|
|
|
2012-01-05 20:12:46 -05:00
|
|
|
class CleanLoggerTest < ActiveSupport::TestCase
|
2005-10-13 15:05:32 -04:00
|
|
|
def setup
|
|
|
|
@out = StringIO.new
|
2011-12-19 21:41:37 -05:00
|
|
|
@logger = ActiveSupport::Logger.new(@out)
|
2005-10-13 15:05:32 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_format_message
|
2016-08-06 12:03:25 -04:00
|
|
|
@logger.error "error"
|
2005-10-13 15:05:32 -04:00
|
|
|
assert_equal "error\n", @out.string
|
|
|
|
end
|
|
|
|
|
2007-02-24 19:07:54 -05:00
|
|
|
def test_datetime_format
|
|
|
|
@logger.formatter = Logger::Formatter.new
|
2011-12-19 21:41:37 -05:00
|
|
|
@logger.formatter.datetime_format = "%Y-%m-%d"
|
2016-08-06 12:03:25 -04:00
|
|
|
@logger.debug "debug"
|
2011-12-19 21:41:37 -05:00
|
|
|
assert_equal "%Y-%m-%d", @logger.formatter.datetime_format
|
2021-12-20 17:36:33 -05:00
|
|
|
assert_match(/D, \[\d\d\d\d-\d\d-\d\d[ ]?#\d+\] DEBUG -- : debug/, @out.string)
|
2007-02-24 19:07:54 -05:00
|
|
|
end
|
2010-08-14 01:13:00 -04:00
|
|
|
|
2007-09-22 14:25:30 -04: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 15:05:32 -04:00
|
|
|
end
|