This commit is contained in:
Torsten Ruger 2016-12-06 16:44:04 +02:00
parent fe203b55f1
commit 3ed0c4829a
3 changed files with 41 additions and 1 deletions

View File

@ -18,7 +18,7 @@ module Logging
module Methods module Methods
def log def log
return @logger if @logger return @logger if @logger
@logger = Logger.new STDOUT @logger = Logger.new log_stream
@logger.progname = self.name.split("::").last @logger.progname = self.name.split("::").last
@logger.datetime_format = '%M:%S' @logger.datetime_format = '%M:%S'
@logger.level = Logger::INFO @logger.level = Logger::INFO
@ -42,5 +42,10 @@ module Logging
raise "unknown log level #{l}" raise "unknown log level #{l}"
end end
end end
private
def log_stream
STDOUT
end
end end
end end

1
test/lib/test_all.rb Normal file
View File

@ -0,0 +1 @@
require_relative "log_test"

34
test/lib/test_log.rb Normal file
View File

@ -0,0 +1,34 @@
require_relative '../helper'
class MemLogger
def self.stream
@stream
end
def self.log_stream
@stream = StringIO.new
end
include Logging
end
class LoggerTest < MiniTest::Test
def setup
@logger = MemLogger.new
end
def test_debug
assert @logger.log.debug "Debug"
end
def test_info
assert @logger.log.info "Info"
assert MemLogger.stream.string.include? "Info"
end
def test_warn
assert @logger.log.warn "Warn"
assert MemLogger.stream.string.include? "Warn"
end
def test_error
assert @logger.log.error "Error"
assert MemLogger.stream.string.include? "Error"
end
end