Class: GenericMonitorLog
- Inherits:
-
Object
- Object
- GenericMonitorLog
- Defined in:
- lib/gml/generic_monitor_log.rb
Overview
This class provides a generic and simple way to log ruby code.
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#entry(log_level = Gml::LOG_LEVEL_INFO, log_entry = "", caller_depth = 1) ⇒ Object
The main method that logs the messages.
-
#initialize(options = {}) ⇒ GenericMonitorLog
constructor
The class constructor.
-
#log_debug(log_entry = "") ⇒ Object
Log a debug message.
-
#log_info(log_entry = "") ⇒ Object
(also: #log)
Log an info message.
-
#log_panic(log_entry = "") ⇒ Object
Log a panic message.
-
#log_trace(log_entry = "") ⇒ Object
Log a trace message.
-
#log_verbose(log_entry = "") ⇒ Object
Log a verbose message.
Constructor Details
#initialize(options = {}) ⇒ GenericMonitorLog
The class constructor.
13 14 15 16 17 |
# File 'lib/gml/generic_monitor_log.rb', line 13 def initialize( = {}) raise StandardError.new("'options' must be a Hash or nil.") if !.is_a?(Hash) = DEFAULT_OPTIONS.merge() end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/gml/generic_monitor_log.rb', line 8 def end |
Instance Method Details
#entry(log_level = Gml::LOG_LEVEL_INFO, log_entry = "", caller_depth = 1) ⇒ Object
The main method that logs the messages.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/gml/generic_monitor_log.rb', line 22 def entry(log_level = Gml::LOG_LEVEL_INFO, log_entry = "", caller_depth = 1) if ((log_level <= [:log_level]) && ([:console] || [:output])) at = caller_locations()[caller_depth] out = "[#{Time.now.strftime(@options[:time_format])}] #{Gml::LOG_STRINGS[log_level]} " out << "[#{File.basename(at.absolute_path)}->#{at.label}: #{at.lineno}]" out << " - " if log_entry.size > 0 out << log_entry [:console].puts(out) if [:console] if ([:output]) if ([:output].is_a?(IO)) [:output].puts(out) else out << "\n" File.write([:output], out, (File.exist?([:output]) ? File.size([:output]) : 0)) end end end end |
#log_debug(log_entry = "") ⇒ Object
Log a debug message. This is a convenience method.
72 73 74 |
# File 'lib/gml/generic_monitor_log.rb', line 72 def log_debug(log_entry = "") entry(Gml::LOG_LEVEL_DEBUG, log_entry, 1) end |
#log_info(log_entry = "") ⇒ Object Also known as: log
Log an info message. This is a convenience method.
56 57 58 |
# File 'lib/gml/generic_monitor_log.rb', line 56 def log_info(log_entry = "") entry(Gml::LOG_LEVEL_INFO, log_entry, 1) end |
#log_panic(log_entry = "") ⇒ Object
Log a panic message. This is a convenience method.
49 50 51 |
# File 'lib/gml/generic_monitor_log.rb', line 49 def log_panic(log_entry = "") entry(Gml::LOG_LEVEL_PANIC, log_entry, 1) end |
#log_trace(log_entry = "") ⇒ Object
Log a trace message. This is a convenience method.
79 80 81 |
# File 'lib/gml/generic_monitor_log.rb', line 79 def log_trace(log_entry = "") entry(Gml::LOG_LEVEL_TRACE, log_entry, 1) end |
#log_verbose(log_entry = "") ⇒ Object
Log a verbose message. This is a convenience method.
65 66 67 |
# File 'lib/gml/generic_monitor_log.rb', line 65 def log_verbose(log_entry = "") entry(Gml::LOG_LEVEL_VERBOSE, log_entry, 1) end |