require 'test/unit' require 'stringio' require 'eymiha/util/easylog' include Eymiha class TC_log < Test::Unit::TestCase def teardown finish_logging end def test_debug log = StringIO.new start_logging log log_debug "logging" assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* DEBUG logging \(TC_log\)/ =~ log.string) end def test_info log = StringIO.new start_logging log log_info "logging" assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO logging \(TC_log\)/ =~ log.string) end def test_warn log = StringIO.new start_logging log log_warn "logging" assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* WARN logging \(TC_log\)/ =~ log.string) end def test_error log = StringIO.new start_logging log log_error "logging" assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* ERROR logging \(TC_log\)/ =~ log.string) end def test_fatal log = StringIO.new start_logging log log_fatal "logging" assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* FATAL logging \(TC_log\)/ =~ log.string) end def test_easylogger_instance log1 = StringIO.new logger1 = EasyLogger.new(log1) log2 = StringIO.new logger2 = EasyLogger.new(log2) logger1.info("once") logger2.info("twice") assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO once/ =~ log1.string) assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO twice/ =~ log2.string) end def test_change_log log1 = StringIO.new log2 = StringIO.new start_logging log1 logger2 = EasyLogger.new(log2) log_info "once" change_easylogger logger2 log_info "twice" assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO once \(TC_log\)/ =~ log1.string) assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO twice \(TC_log\)/ =~ log2.string) end def test_multi_log log1 = StringIO.new log2 = StringIO.new start_logging log1 logger2 = EasyLogger.new(log2) log_info "once" log_info "twice",logger2 assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO once \(TC_log\)/ =~ log1.string) assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO twice \(TC_log\)/ =~ log2.string) end def test_change_classify log = StringIO.new start_logging log easylogger.classify = false log_info "logging" assert(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO logging/ =~ log.string) assert(!(/\d\d\/\d\d\/\d\d \d\d:\d\d:\d\d.\d* INFO logging \(/ =~ log.string)) end end