class MCollective::Logger::Console_logger

Impliments a syslog based logger using the standard ruby syslog class

Public Instance Methods

color(level) click to toggle source

Set some colors for various logging levels, will honor the color configuration option and return nothing if its configured not to

# File lib/mcollective/logger/console_logger.rb, line 39
def color(level)
    colorize = Config.instance.color

    colors = {:error => "",
              :fatal => "",
              :warn => "",
              :info => "",
              :reset => ""}

    if colorize
        return colors[level] || ""
    else
        return ""
    end
end
colorize(level, msg) click to toggle source

Helper to return a string in specific color

# File lib/mcollective/logger/console_logger.rb, line 56
def colorize(level, msg)
    "#{self.color(level)}#{msg}#{self.color(:reset)}"
end
log(level, from, msg) click to toggle source
# File lib/mcollective/logger/console_logger.rb, line 24
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_logging_level(level) click to toggle source
# File lib/mcollective/logger/console_logger.rb, line 12
def set_logging_level(level)
    # nothing to do here, we ignore high levels when we log
end
start() click to toggle source
# File lib/mcollective/logger/console_logger.rb, line 5
def start
    set_level(:info)

    config = Config.instance
    set_level(config.loglevel.to_sym) if config.configured
end
valid_levels() click to toggle source
# File lib/mcollective/logger/console_logger.rb, line 16
def valid_levels
    {:info  => :info,
     :warn  => :warning,
     :debug => :debug,
     :fatal => :crit,
     :error => :err}
end