Module: Facter::Core::Logging
Constant Summary collapse
- GREEN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"[0;32m"
- RESET =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"[0m"
- @@debug =
This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.
false
- @@timing =
This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.
false
- @@trace =
This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.
false
- @@warn_messages =
This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.
{}
- @@debug_messages =
This classvariable is part of a private API. You should avoid using this classvariable if possible, as it may be removed or be changed in the future.
{}
Instance Method Summary collapse
-
#clear_messages ⇒ void
private
Clears the seen state of warning messages.
-
#debug(msg) ⇒ void
Prints a debug message if debugging is turned on.
-
#debugging(bool) ⇒ void
private
Enable or disable logging of debug messages.
-
#debugging? ⇒ true, false
private
Is debugging enabled?.
-
#debugonce(msg) ⇒ void
Prints a debug message only once.
- #format_exception(exception, message, trace) ⇒ Object
- #log_exception(exception, message = :default) ⇒ Object
-
#show_time(string) ⇒ void
private
Print timing information.
-
#timing(bool) ⇒ void
private
Enable or disable logging of timing information.
-
#timing? ⇒ Boolean
private
Returns whether timing output is turned on.
- #trace(bool) ⇒ Object
- #trace? ⇒ Boolean
-
#warn(msg) ⇒ void
Prints a warning message.
-
#warnonce(msg) ⇒ void
Prints a warning message only once per process.
Instance Method Details
#clear_messages ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Clears the seen state of warning messages. See #warnonce.
166 167 168 |
# File 'lib/facter/core/logging.rb', line 166 def @@warn_messages.clear end |
#debug(msg) ⇒ void
This method returns an undefined value.
Prints a debug message if debugging is turned on
28 29 30 31 32 33 34 35 36 37 |
# 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 |
#debugging(bool) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Enable or disable logging of debug messages
123 124 125 |
# File 'lib/facter/core/logging.rb', line 123 def debugging(bool) @@debug = bool end |
#debugging? ⇒ true, false
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Is debugging enabled?
132 133 134 |
# File 'lib/facter/core/logging.rb', line 132 def debugging? @@debug end |
#debugonce(msg) ⇒ void
Uniqueness is based on the string, not the specific location of the method call.
This method returns an undefined value.
Prints a debug message only once.
46 47 48 49 50 51 |
# 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 |
#format_exception(exception, message, trace) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/facter/core/logging.rb', line 89 def format_exception(exception, , trace) arr = [] if == :default arr << exception. elsif arr << end if trace arr.concat(exception.backtrace) end arr.flatten.join("\n") end |
#log_exception(exception, message = :default) ⇒ Object
85 86 87 |
# File 'lib/facter/core/logging.rb', line 85 def log_exception(exception, = :default) self.warn(format_exception(exception, , @@trace)) end |
#show_time(string) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Print timing information
113 114 115 |
# File 'lib/facter/core/logging.rb', line 113 def show_time(string) $stderr.puts "#{GREEN}#{string}#{RESET}" if string and self.timing? end |
#timing(bool) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Enable or disable logging of timing information
142 143 144 |
# File 'lib/facter/core/logging.rb', line 142 def timing(bool) @@timing = bool end |
#timing? ⇒ Boolean
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns whether timing output is turned on
149 150 151 |
# File 'lib/facter/core/logging.rb', line 149 def timing? @@timing end |
#trace(bool) ⇒ Object
153 154 155 |
# File 'lib/facter/core/logging.rb', line 153 def trace(bool) @@trace = bool end |
#trace? ⇒ Boolean
157 158 159 |
# File 'lib/facter/core/logging.rb', line 157 def trace? @@trace end |
#warn(msg) ⇒ void
This method returns an undefined value.
Prints a warning message. The message is only printed if debugging is enabled.
59 60 61 62 63 64 65 66 |
# 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 |
#warnonce(msg) ⇒ void
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.
This method returns an undefined value.
Prints a warning message only once per process. Each unique string is printed once.
78 79 80 81 82 83 |
# 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 |