Class: MCollective::Logger::Console_logger
- Defined in:
- lib/mcollective/logger/console_logger.rb
Overview
Implements a syslog based logger using the standard ruby syslog class
Direct Known Subclasses
Util::Playbook::Playbook_Logger, Util::Playbook::Puppet_Logger
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#color(level) ⇒ Object
Set some colors for various logging levels, will honor the color configuration option and return nothing if its configured not to.
-
#colorize(level, msg) ⇒ Object
Helper to return a string in specific color.
- #log(level, from, msg, normal_output = $stderr, last_resort_output = $stderr) ⇒ Object
-
#set_logging_level(level) ⇒ Object
rubocop:disable Naming/AccessorMethodName.
- #start ⇒ Object
- #valid_levels ⇒ Object
Methods inherited from Base
#cycle_level, #initialize, #reopen, #set_level
Constructor Details
This class inherits a constructor from MCollective::Logger::Base
Instance Method Details
#color(level) ⇒ Object
Set some colors for various logging levels, will honor the color configuration option and return nothing if its configured not to
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/mcollective/logger/console_logger.rb', line 39 def color(level) colorize = Config.instance.color colors = {:error => Util.color(:red), :fatal => Util.color(:red), :warn => Util.color(:yellow), :info => Util.color(:green), :reset => Util.color(:reset)} if colorize colors[level] || "" else "" end end |
#colorize(level, msg) ⇒ Object
Helper to return a string in specific color
56 57 58 |
# File 'lib/mcollective/logger/console_logger.rb', line 56 def colorize(level, msg) "%s%s%s" % [color(level), msg, color(:reset)] end |
#log(level, from, msg, normal_output = $stderr, last_resort_output = $stderr) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/mcollective/logger/console_logger.rb', line 24 def log(level, from, msg, normal_output=$stderr, last_resort_output=$stderr) if @known_levels.index(level) >= @known_levels.index(@active_level) time = Time.new.strftime("%Y/%m/%d %H:%M:%S") normal_output.puts("%s %s: %s %s" % [colorize(level, level), time, from, msg]) end rescue # if this fails we probably cant show the user output at all, # STDERR it as last resort last_resort_output.puts("#{level}: #{msg}") end |
#set_logging_level(level) ⇒ Object
rubocop:disable Naming/AccessorMethodName
12 13 14 |
# File 'lib/mcollective/logger/console_logger.rb', line 12 def set_logging_level(level) # rubocop:disable Naming/AccessorMethodName # nothing to do here, we ignore high levels when we log end |
#start ⇒ Object
5 6 7 8 9 10 |
# 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 ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/mcollective/logger/console_logger.rb', line 16 def valid_levels {:info => :info, :warn => :warning, :debug => :debug, :fatal => :crit, :error => :err} end |