lib/onering/logger.rb in onering-client-0.0.91 vs lib/onering/logger.rb in onering-client-0.0.92
- old
+ new
@@ -3,10 +3,11 @@
module Onering
class Logger
def self.setup(options={})
outputfn = options[:destination]
+ @_verbosity = 1
if options[:destination] == /STDOUT/i
options[:destination] = STDOUT
elsif options[:destination] == /STDERR/i or
@@ -39,11 +40,11 @@
logline = logline.foreground(:red)
when :warn
logline = logline.foreground(:yellow)
when :info
logline = logline.foreground(:green)
- when :debug
+ when :debug, :debug2, :debug3
logline = logline.foreground(:blue)
end
end
options[:destination].puts(logline)
@@ -55,17 +56,21 @@
self.debug("Logger is initialized. Output is #{outputfn}, threshold: #{options[:threshold]} or worse", "Onering::Logger")
end
def self.level=(severity)
@_logger.sev_threshold = _get_level(severity)
+ @_verbosity = (Integer(severity.to_s[-1]) rescue 1)
+
@_logger.sev_threshold
end
- def self.log(severity, message, source=nil)
+ def self.log(severity, message, source=nil, verbosity=1)
if defined?(@_logger)
- @_logger.add(_get_level(severity), message, source)
- return true
+ if @_verbosity >= verbosity
+ @_logger.add(_get_level(severity), message, source)
+ return true
+ end
end
return false
end
@@ -90,9 +95,17 @@
self.log(:info, message, source)
end
def self.debug(message, source=nil)
self.log(:debug, message, source)
+ end
+
+ def self.debug2(message, source=nil)
+ self.log(:debug, message, source, 2)
+ end
+
+ def self.debug3(message, source=nil)
+ self.log(:debug, message, source, 3)
end
def self._get_level(severity)
case severity.to_sym
when :fatal
\ No newline at end of file