use modified opal logger
logger was having bizarre format errors copied and simplified (to get on)
This commit is contained in:
52
lib/util/logging.rb
Normal file
52
lib/util/logging.rb
Normal 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
|
Reference in New Issue
Block a user