Sha256: 5c0ed92f814e066e064e6cd0aac4fe6c242087d90819920ea247563a43a224d5

Contents?: true

Size: 1.2 KB

Versions: 15

Compression:

Stored size: 1.2 KB

Contents

# -*- encoding: utf-8 -*-

require 'minitest/autorun'
require 'stringio'
require 'webgen/logger'

class TestLogger < Minitest::Test

  def test_logging
    @logio = StringIO.new
    logger = Webgen::Logger.new(@logio)
    logger.formatter = Proc.new do |severity, timestamp, progname, msg|
      "#{severity} #{msg}\n"
    end

    logger.verbose = false
    logger.debug { ["debug", "verbose"]}
    assert_log(/^DEBUG debug$/)
    logger.info {["info", "verbose"]}
    assert_log(/^INFO info$/)
    logger.warn {["warn", "verbose"]}
    assert_log(/^WARN warn$/)
    logger.error {["error", "verbose"]}
    assert_log(/^ERROR error$/)
    logger.vinfo {["verbose", "verbose"]}
    assert_log(/^$/)

    logger.verbose = true
    logger.debug { ["debug", "verbose"]}
    assert_log(/^DEBUG debug\nverbose$/)
    logger.info {["info", "verbose"]}
    assert_log(/^INFO info\nverbose$/)
    logger.warn {["warn", "verbose"]}
    assert_log(/^WARN warn\nverbose$/)
    logger.error {["error", "verbose"]}
    assert_log(/^ERROR error\nverbose$/)
    logger.vinfo {["verbose", "verbose"]}
    assert_log(/^INFO verbose\nverbose$/)
  end

  def assert_log(reg)
    assert_match(reg, @logio.string)
    @logio.string = ''
  end

end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
webgen-1.7.3 test/webgen/test_logger.rb
webgen-1.7.2 test/webgen/test_logger.rb
webgen-1.7.1 test/webgen/test_logger.rb
webgen-1.7.0 test/webgen/test_logger.rb
webgen-1.6.0 test/webgen/test_logger.rb
webgen-1.5.2 test/webgen/test_logger.rb
webgen-1.5.1 test/webgen/test_logger.rb
webgen-1.5.0 test/webgen/test_logger.rb
webgen-1.4.1 test/webgen/test_logger.rb
webgen-1.4.0 test/webgen/test_logger.rb
webgen-1.3.0 test/webgen/test_logger.rb
webgen-1.2.1 test/webgen/test_logger.rb
webgen-1.2.0 test/webgen/test_logger.rb
webgen-1.1.0 test/webgen/test_logger.rb
webgen-1.0.0 test/webgen/test_logger.rb