use modified opal logger

logger was having bizarre format errors
copied and simplified (to get on)
This commit is contained in:
Torsten Ruger
2018-05-20 14:45:48 +03:00
parent a350325b6b
commit a7a62d53b2
8 changed files with 694 additions and 58 deletions

52
lib/util/logging.rb Normal file
View File

@ -0,0 +1,52 @@
# a simple module to be included into a class that want to log
#
# use the standard logger and the class name as the program name
#
# The standard functions are available on the log object
# And the log level may be set after inclusion with level function (that takes symbols)
require_relative "logger"
module Util
module Logging
def self.included(base)
base.extend(Methods)
end
def log
self.class.log
end
module Methods
def log
return @logger if @logger
@logger = Logger.new log_stream
@logger.progname = self.name.split("::").last
@logger.level = Logger::INFO
@logger
end
def log_level l
log.level = case l
when :unknown
Logger::UNKNOWN
when :fatal
Logger::FATAL
when :error
Logger::ERROR
when :warn
Logger::WARN
when :info
Logger::INFO
when :debug
Logger::DEBUG
else
raise "unknown log level #{l}"
end
end
private
def log_stream
STDOUT
end
end
end
end