class DoSnapshot::Log
Shared logger
Attributes
buffer[W]
instance[W]
quiet[RW]
shell[R]
verbose[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/do_snapshot/log.rb, line 13 def initialize(options = {}) @verbose = DoSnapshot.config.verbose @quiet = DoSnapshot.config.quiet options.each { |key, option| instance_variable_set(:"@#{key}", option) } instance.level = DoSnapshot.config.logger_level if instance Hashie.logger = self end
Public Instance Methods
buffer()
click to toggle source
# File lib/do_snapshot/log.rb, line 25 def buffer @buffer ||= %w() end
close()
click to toggle source
# File lib/do_snapshot/log.rb, line 33 def close instance.close if instance end
instance()
click to toggle source
# File lib/do_snapshot/log.rb, line 21 def instance @instance ||= DoSnapshot.config.logger end
log(severity, message = nil, progname = nil, &block)
click to toggle source
# File lib/do_snapshot/log.rb, line 41 def log(severity, message = nil, progname = nil, &block) buffer << message instance.add(severity, message, progname, &block) if instance say message, color(severity) unless print?(severity) end
shell=(shell)
click to toggle source
# File lib/do_snapshot/log.rb, line 29 def shell=(shell) @shell = shell unless quiet end
Protected Instance Methods
color(severity)
click to toggle source
# File lib/do_snapshot/log.rb, line 58 def color(severity) case severity when 0 :white when 3 :red when 2 :yellow else :green end end
print?(type)
click to toggle source
# File lib/do_snapshot/log.rb, line 50 def print?(type) (type == :debug && !verbose) || quiet end
say(message, color)
click to toggle source
# File lib/do_snapshot/log.rb, line 54 def say(message, color) shell.say message, color if shell end