Clears the seen state of warning messages. See {warnonce}.
@return [void]
@api private
# File lib/facter/core/logging.rb, line 166 def clear_messages @@warn_messages.clear end
Prints a debug message if debugging is turned on
@param msg [String] the debug message @return [void]
# File lib/facter/core/logging.rb, line 28 def debug(msg) if self.debugging? if msg.nil? or msg.empty? invoker = caller[0].slice(/.*:\d+/) self.warn "#{self.class}#debug invoked with invalid message #{msg.inspect}:#{msg.class} at #{invoker}" else puts GREEN + msg + RESET end end end
Enable or disable logging of debug messages
@param bool [true, false] @return [void]
@api private
# File lib/facter/core/logging.rb, line 123 def debugging(bool) @@debug = bool end
Is debugging enabled?
@return [true, false]
@api private
# File lib/facter/core/logging.rb, line 132 def debugging? @@debug end
Prints a debug message only once.
@note Uniqueness is based on the string, not the specific location
of the method call.
@param msg [String] the debug message @return [void]
# File lib/facter/core/logging.rb, line 46 def debugonce(msg) if msg and not msg.empty? and @@debug_messages[msg].nil? @@debug_messages[msg] = true debug(msg) end end
# File lib/facter/core/logging.rb, line 89 def format_exception(exception, message, trace) arr = [] if message == :default arr << exception.message elsif message arr << message end if trace arr.concat(exception.backtrace) end arr.flatten.join("\n") end
# File lib/facter/core/logging.rb, line 85 def log_exception(exception, message = :default) self.warn(format_exception(exception, message, @@trace)) end
Print timing information
@param string [String] the time to print @return [void]
@api private
# File lib/facter/core/logging.rb, line 113 def show_time(string) $stderr.puts "#{GREEN}#{string}#{RESET}" if string and self.timing? end
Enable or disable logging of timing information
@param bool [true, false] @return [void]
@api private
# File lib/facter/core/logging.rb, line 142 def timing(bool) @@timing = bool end
Returns whether timing output is turned on
@api private
# File lib/facter/core/logging.rb, line 149 def timing? @@timing end
# File lib/facter/core/logging.rb, line 153 def trace(bool) @@trace = bool end
Prints a warning message. The message is only printed if debugging is enabled.
@param msg [String] the warning message to be printed
@return [void]
# File lib/facter/core/logging.rb, line 59 def warn(msg) if msg.nil? or msg.empty? invoker = caller[0].slice(/.*:\d+/) Kernel.warn "#{self.class}#debug invoked with invalid message #{msg.inspect}:#{msg.class} at #{invoker}" else Kernel.warn msg end end
Prints a warning message only once per process. Each unique string is printed once.
@note Unlike {warn} the message will be printed even if debugging is
not turned on. This behavior is likely to change and should not be relied on.
@param msg [String] the warning message to be printed
@return [void]
# File lib/facter/core/logging.rb, line 78 def warnonce(msg) if @@warn_messages[msg].nil? self.warn(msg) @@warn_messages[msg] = true end end
Generated with the Darkfish Rdoc Generator 2.