class Facter::Log
Public Class Methods
Source
# File lib/facter/framework/logging/logger.rb, line 24 def clear_messages @@debug_messages.clear @@warn_messages.clear end
Source
# File lib/facter/framework/logging/logger.rb, line 41 def errors? @@has_errors end
Source
# File lib/facter/framework/logging/logger.rb, line 33 def level=(log_level) @@logger.level = log_level end
Source
# File lib/facter/framework/logging/logger.rb, line 96 def initialize(logged_class) @class_name = LoggerHelper.determine_callers_name(logged_class) return unless @@logger.nil? @@logger = Logger.new(STDOUT) @@logger.level = DEFAULT_LOG_LEVEL end
Source
# File lib/facter/framework/logging/logger.rb, line 29 def on_message(&block) @@message_callback = block end
Source
# File lib/facter/framework/logging/logger.rb, line 45 def output(output) return if @@logger @@logger = Logger.new(output) set_logger_format @@logger.level = DEFAULT_LOG_LEVEL end
Source
# File lib/facter/framework/logging/logger.rb, line 53 def set_logger_format @@logger.formatter = proc do |severity, datetime, _progname, msg| datetime = datetime.strftime(@datetime_format || '%Y-%m-%d %H:%M:%S.%6N ') "[#{datetime}] #{severity} #{msg} \n" end end
Source
# File lib/facter/framework/logging/logger.rb, line 68 def show_time(string) return unless string && timing? if @@message_callback @@message_callback.call(:info, string) else warn("#{GREEN}#{string}#{RESET}") end end
Print timing information
@param string [String] the time to print @return [void]
@api private
Source
# File lib/facter/framework/logging/logger.rb, line 84 def timing(bool) @@timing = bool end
Enable or disable logging of timing information
@param bool [true, false] @return [void]
@api private
Source
# File lib/facter/framework/logging/logger.rb, line 91 def timing? @@timing end
Returns whether timing output is turned on
@api private
Public Instance Methods
Source
# File lib/facter/framework/logging/logger.rb, line 104 def debug(msg) return unless debugging_active? if @@message_callback && Options[:allow_external_loggers] @@message_callback.call(:debug, msg) else msg = colorize(msg, CYAN) if Options[:color] @@logger.debug("#{@class_name} - #{msg}") end end
Source
# File lib/facter/framework/logging/logger.rb, line 115 def debugonce(msg) return unless debugging_active? message_string = msg.to_s return if @@debug_messages.include? message_string @@debug_messages << message_string debug(message_string) end
Source
# File lib/facter/framework/logging/logger.rb, line 153 def error(msg, colorize = false) # rubocop:disable Style/OptionalBooleanParameter @@has_errors = true if @@message_callback && Options[:allow_external_loggers] @@message_callback.call(:error, msg) else msg = colorize(msg, RED) if colorize || Options[:color] @@logger.error("#{@class_name} - #{msg}") end end
Source
# File lib/facter/framework/logging/logger.rb, line 125 def info(msg) if msg.nil? || msg.empty? empty_message_error(msg) elsif @@message_callback && Options[:allow_external_loggers] @@message_callback.call(:info, msg) else msg = colorize(msg, GREEN) if Options[:color] @@logger.info("#{@class_name} - #{msg}") end end
Source
# File lib/facter/framework/logging/logger.rb, line 164 def log_exception(exception) msg = exception.message msg += "\n#{exception.backtrace.join("\n")}" if Options[:trace] error(msg, true) end
Source
# File lib/facter/framework/logging/logger.rb, line 136 def warn(msg) if @@message_callback && Options[:allow_external_loggers] @@message_callback.call(:warn, msg) else msg = colorize(msg, YELLOW) if Options[:color] @@logger.warn("#{@class_name} - #{msg}") end end
Source
# File lib/facter/framework/logging/logger.rb, line 145 def warnonce(message) message_string = message.to_s return if @@warn_messages.include? message_string @@warn_messages << message_string warn(message_string) end
Private Instance Methods
Source
# File lib/facter/framework/logging/logger.rb, line 173 def colorize(msg, color) "#{color}#{msg}#{RESET}" end
Source
# File lib/facter/framework/logging/logger.rb, line 177 def debugging_active? return true unless Facter.respond_to?(:debugging?) Facter.debugging? end
Source
# File lib/facter/framework/logging/logger.rb, line 183 def empty_message_error(msg) invoker = caller(1..1).first.slice(/.*:\d+/) @@logger.warn "#{self.class}#debug invoked with invalid message #{msg.inspect}:#{msg.class} at #{invoker}" end