Sha256: 1e278d8a375321f428d4bf244b9b6e33d5d65c4f1c848dbf21404fbcaa55a455
Contents?: true
Size: 1.63 KB
Versions: 2
Compression:
Stored size: 1.63 KB
Contents
module MCollective module Logger # Impliments a syslog based logger using the standard ruby syslog class class Console_logger<Base def start set_level(:info) config = Config.instance set_level(config.loglevel.to_sym) if config.configured end def set_logging_level(level) # nothing to do here, we ignore high levels when we log end def valid_levels {:info => :info, :warn => :warning, :debug => :debug, :fatal => :crit, :error => :err} end def log(level, from, msg) if @known_levels.index(level) >= @known_levels.index(@active_level) time = Time.new.strftime("%Y/%m/%d %H:%M:%S") lvltxt = colorize(level, level) STDERR.puts("#{lvltxt} #{time}: #{from} #{msg}") end rescue # if this fails we probably cant show the user output at all, # STDERR it as last resort STDERR.puts("#{level}: #{msg}") end # Set some colors for various logging levels, will honor the # color configuration option and return nothing if its configured # not to def color(level) colorize = Config.instance.color colors = {:error => "[31m", :fatal => "[31m", :warn => "[33m", :info => "[32m", :reset => "[0m"} if colorize return colors[level] || "" else return "" end end # Helper to return a string in specific color def colorize(level, msg) "#{self.color(level)}#{msg}#{self.color(:reset)}" end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
mcollective-client-2.0.0 | lib/mcollective/logger/console_logger.rb |
mcollective-client-1.3.3 | lib/mcollective/logger/console_logger.rb |