aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test/clean_logger_test.rb
blob: 6d8f7064cef60a75ca8dc36162b27db60c6fb0c8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

require "abstract_unit"
require "stringio"
require "active_support/logger"

class CleanLoggerTest < ActiveSupport::TestCase
  def setup
    @out = StringIO.new
    @logger = ActiveSupport::Logger.new(@out)
  end

  def test_format_message
    @logger.error "error"
    assert_equal "error\n", @out.string
  end

  def test_datetime_format
    @logger.formatter = Logger::Formatter.new
    @logger.formatter.datetime_format = "%Y-%m-%d"
    @logger.debug "debug"
    assert_equal "%Y-%m-%d", @logger.formatter.datetime_format
    assert_match(/D, \[\d\d\d\d-\d\d-\d\d#\d+\] DEBUG -- : debug/, @out.string)
  end

  def test_nonstring_formatting
    an_object = [1, 2, 3, 4, 5]
    @logger.debug an_object
    assert_equal("#{an_object.inspect}\n", @out.string)
  end
end