aboutsummaryrefslogtreecommitdiff
path: root/test/tc_mauve_configuration_builders_logger.rb
blob: 14df0d8b07e166929c25268bb8a10796fb9c2e29 (plain)
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
$:.unshift "../lib/"

require 'th_mauve'
require 'mauve/configuration_builders/logger'
require 'tempfile'

class TcMauveConfigurationBuildersLogger < Mauve::UnitTest

  def setup
  end

  def test_load

    test_log = Tempfile.new(self.class.to_s)

    config=<<EOF
logger {
  default_format "%d [ %l ] [ %12.12c ] %m"
  default_level WARN

  outputter "stdout"

  outputter ("file") {
    trunc false
    filename "#{test_log.path}"
    level DEBUG
  }

}
EOF

    assert_nothing_raised { Mauve::ConfigurationBuilder.parse(config) }
    
    #
    # Check that we've got the correct things set
    #
    logger = nil
    assert_nothing_raised { logger = Log4r::Logger.get("Mauve") }
    assert_equal(2, logger.outputters.length)

    outputter = logger.outputters[0]

    assert_kind_of(Log4r::StdoutOutputter, outputter)
    assert_equal("%d [ %l ] [ %12.12c ] %m", outputter.formatter.pattern )
    assert_equal(Log4r::WARN, outputter.level )

    outputter = logger.outputters[1]
    assert_kind_of(Log4r::FileOutputter, outputter)
    assert_equal("%d [ %l ] [ %12.12c ] %m", outputter.formatter.pattern )
    assert_equal(Log4r::DEBUG, outputter.level )
    assert_equal(false, outputter.trunc )
    assert_equal(test_log.path, outputter.filename )
  end

  def test_levels
    #
    # Make sure our levels match those of log4r.
    #
    %w(DEBUG WARN FATAL ERROR INFO).each do |l|
      assert_equal(Log4r.const_get(l), Mauve::LoggerConstants.const_get(l))
    end
  end

end