Class: MiqDevUtil::Logger
- Inherits:
-
Object
- Object
- MiqDevUtil::Logger
- Defined in:
- lib/miq_dev_util/logger.rb
Overview
A utility class to write information to the ManageIQ logs.
Instance Method Summary collapse
- #debug(message) ⇒ Object
-
#dump_associations(my_object, my_object_name) ⇒ Object
Write the associations of the given object to the log with a prefix of my_object_name to make finding the entries a little easier.
-
#dump_attributes(my_object, my_object_name) ⇒ Object
Write the attributes of the given object to the log with a prefix of my_object_name to make finding the entries a little easier.
-
#dump_info(my_object, my_object_name) ⇒ Object
A shortcut for dumping multiple types of information about the given object.
-
#dump_root ⇒ Object
A shortcut to dump the $evm.root object.
-
#dump_virtual_columns(my_object, my_object_name) ⇒ Object
Write the virtual columns of the given object to the log with a prefix of my_object_name to make finding the entries a little easier.
- #error(message) ⇒ Object
- #info(message) ⇒ Object
-
#initialize(evm, method_name) ⇒ Logger
constructor
A new instance of Logger.
-
#log(level, message) ⇒ Object
Write message to the logging system with the given logging level.
- #warn(message) ⇒ Object
Constructor Details
#initialize(evm, method_name) ⇒ Logger
Returns a new instance of Logger.
4 5 6 7 8 |
# File 'lib/miq_dev_util/logger.rb', line 4 def initialize(evm, method_name) @evm = evm @method_name = method_name @dump_log_level = :info end |
Instance Method Details
#debug(message) ⇒ Object
15 16 17 |
# File 'lib/miq_dev_util/logger.rb', line 15 def debug() log(:debug, ) end |
#dump_associations(my_object, my_object_name) ⇒ Object
Write the associations of the given object to the log with a prefix of my_object_name to make finding the entries a little easier.
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/miq_dev_util/logger.rb', line 46 def dump_associations(my_object, my_object_name) if my_object.respond_to?("associations") self.log(@dump_log_level, "Begin #{my_object_name}.associations") my_object.associations.sort.each { |a| self.log(:info, "#{my_object_name} Association - #{a}")} self.log(@dump_log_level, "End #{my_object_name}.associations") self.log(@dump_log_level, "") else self.log(@dump_log_level, "No associations for #{my_object_name}") end end |
#dump_attributes(my_object, my_object_name) ⇒ Object
Write the attributes of the given object to the log with a prefix of my_object_name to make finding the entries a little easier.
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/miq_dev_util/logger.rb', line 33 def dump_attributes(my_object, my_object_name) if my_object.respond_to?("attributes") self.log(@dump_log_level, "Begin #{my_object_name}.attributes") my_object.attributes.sort.each { |k, v| self.log(:info, "#{my_object_name} Attribute - #{k}: #{v}")} self.log(@dump_log_level, "End #{my_object_name}.attributes") self.log(@dump_log_level, "") else self.log(@dump_log_level, "No attributes for #{my_object_name}") end end |
#dump_info(my_object, my_object_name) ⇒ Object
A shortcut for dumping multiple types of information about the given object.
71 72 73 74 75 |
# File 'lib/miq_dev_util/logger.rb', line 71 def dump_info(my_object, my_object_name) self.dump_attributes(my_object, my_object_name) self.dump_associations(my_object, my_object_name) self.dump_virtual_columns(my_object, my_object_name) end |
#dump_root ⇒ Object
A shortcut to dump the $evm.root object.
78 79 80 |
# File 'lib/miq_dev_util/logger.rb', line 78 def dump_root() self.dump_info(@evm.root, "$evm.root") end |
#dump_virtual_columns(my_object, my_object_name) ⇒ Object
Write the virtual columns of the given object to the log with a prefix of my_object_name to make finding the entries a little easier.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/miq_dev_util/logger.rb', line 59 def dump_virtual_columns(my_object, my_object_name) if my_object.respond_to?("virtual_column_names") self.log(@dump_log_level, "Begin #{my_object_name}.virtual_columns") my_object.virtual_column_names.sort.each { |vcn| self.log(:info, "#{my_object_name} Virtual Column - #{vcn}")} self.log(@dump_log_level, "End #{my_object_name}.virtual_columns") self.log(@dump_log_level, "") else log(@dump_log_level, "No virtual_columns for #{my_object_name}") end end |
#error(message) ⇒ Object
19 20 21 |
# File 'lib/miq_dev_util/logger.rb', line 19 def error() log(:error, ) end |
#info(message) ⇒ Object
23 24 25 |
# File 'lib/miq_dev_util/logger.rb', line 23 def info() log(:info, ) end |
#log(level, message) ⇒ Object
Write message to the logging system with the given logging level.
11 12 13 |
# File 'lib/miq_dev_util/logger.rb', line 11 def log(level, ) @evm.log(level, "#{@method_name} - #{message}") end |
#warn(message) ⇒ Object
27 28 29 |
# File 'lib/miq_dev_util/logger.rb', line 27 def warn() log(:warn, ) end |