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
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 39: def color(level) 40: colorize = Config.instance.color 41: 42: colors = {:error => "[31m", 43: :fatal => "[31m", 44: :warn => "[33m", 45: :info => "[32m", 46: :reset => "[0m"} 47: 48: if colorize 49: return colors[level] || "" 50: else 51: return "" 52: end 53: end
# File lib/mcollective/logger/console_logger.rb, line 24 24: def log(level, from, msg) 25: if @known_levels.index(level) >= @known_levels.index(@active_level) 26: time = Time.new.strftime("%Y/%m/%d %H:%M:%S") 27: lvltxt = colorize(level, level) 28: STDERR.puts("#{lvltxt} #{time}: #{from} #{msg}") 29: end 30: rescue 31: # if this fails we probably cant show the user output at all, 32: # STDERR it as last resort 33: STDERR.puts("#{level}: #{msg}") 34: end
# File lib/mcollective/logger/console_logger.rb, line 12 12: def set_logging_level(level) 13: # nothing to do here, we ignore high levels when we log 14: end
# File lib/mcollective/logger/console_logger.rb, line 5 5: def start 6: set_level(:info) 7: 8: config = Config.instance 9: set_level(config.loglevel.to_sym) if config.configured 10: end