Class MCollective::Logger::Console_logger
In: lib/mcollective/logger/console_logger.rb
Parent: Base

Impliments a syslog based logger using the standard ruby syslog class

Methods

Public Instance methods

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

[Source]

    # File lib/mcollective/logger/console_logger.rb, line 37
37:             def color(level)
38:                 colorize = Config.instance.color
39: 
40:                 colors = {:error => "",
41:                           :fatal => "",
42:                           :warn => "",
43:                           :info => "",
44:                           :reset => ""}
45: 
46:                 if colorize
47:                     return colors[level] || ""
48:                 else
49:                     return ""
50:                 end
51:             end

Helper to return a string in specific color

[Source]

    # File lib/mcollective/logger/console_logger.rb, line 54
54:             def colorize(level, msg)
55:                 "#{self.color(level)}#{msg}#{self.color(:reset)}"
56:             end

[Source]

    # File lib/mcollective/logger/console_logger.rb, line 22
22:             def log(level, from, msg)
23:                 if @known_levels.index(level) >= @known_levels.index(@active_level)
24:                     time = Time.new.strftime("%Y/%m/%d %H:%M:%S")
25:                     lvltxt = colorize(level, level)
26:                     STDERR.puts("#{lvltxt} #{time}: #{from} #{msg}")
27:                 end
28:             rescue
29:                 # if this fails we probably cant show the user output at all,
30:                 # STDERR it as last resort
31:                 STDERR.puts("#{level}: #{msg}")
32:             end

[Source]

    # File lib/mcollective/logger/console_logger.rb, line 10
10:             def set_logging_level(level)
11:                 # nothing to do here, we ignore high levels when we log
12:             end

[Source]

   # File lib/mcollective/logger/console_logger.rb, line 5
5:             def start
6:                 config = Config.instance
7:                 set_level(config.loglevel.to_sym)
8:             end

[Source]

    # File lib/mcollective/logger/console_logger.rb, line 14
14:             def valid_levels
15:                 {:info  => :info,
16:                  :warn  => :warning,
17:                  :debug => :debug,
18:                  :fatal => :crit,
19:                  :error => :err}
20:             end

[Validate]