Module: Awetestlib::Logging
- Includes:
- ActiveSupport
- Defined in:
- lib/awetestlib/logging.rb,
lib/awetestlib/regression/awetest_dsl.rb
Overview
Logging and reporting.
Class Method Summary collapse
- .included(mod) ⇒ Object deprecated Deprecated.
Instance Method Summary collapse
- #calculate_durations(tag, t = Time.now.utc) ⇒ Object
- #debug_to_log(message, wai_lvl = 3) (also: #debug_tolog)
- #debug_to_report(message, wai_lvl = 4)
- #error_to_log(message, wai_lvl = 3, exception = nil) (also: #error_tolog)
- #failed_to_log(message, wai_lvl = 3, exception = nil) (also: #validate_failed_tolog, #validate_failed_to_log, #failed_tolog, #fail_tolog, #fail_to_log)
- #fatal_to_log(message, wai_lvl = 3, exception = nil) (also: #fatal_tolog)
- #first_script_index(script = @myName) ⇒ Object
- #info_to_log(message, wai_lvl = 1) (also: #message_tolog, #message_to_log, #info_tolog)
-
#mark_test_level(message = '', lvl = nil, desc = '', caller = 1, wai_lvl = 4, trc = $debug) ⇒ Boolean
(also: #mark_testlevel)
Write a status message to the log and report indicating location or activity in the script.
-
#message_to_report(message, wai_lvl = 4) ⇒ Boolean
Always returns true.
- #passed_to_log(message, wai_lvl = 3, dbg = false) (also: #validate_passed_tolog, #validate_passed_to_log, #passed_tolog, #pass_tolog, #pass_to_log)
- #where_am_i?(index = 2) ⇒ Boolean
- #with_caller(message = '', *strings) ⇒ Object (also: #message_with_caller, #msg_with_caller)
Class Method Details
.included(mod) ⇒ Object
7 8 9 |
# File 'lib/awetestlib/logging.rb', line 7 def self.included(mod) # puts "RegressionSupport::Logging extended by #{mod}" end |
Instance Method Details
#calculate_durations(tag, t = Time.now.utc) ⇒ Object
369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/awetestlib/logging.rb', line 369 def calculate_durations(tag, t = Time.now.utc) last_log_ts ||= t last_lvl_ts ||= t last_val_ts ||= t log_dur = "%9.5f" % (t.to_f - last_log_ts.to_f) lvl_dur = "%9.5f" % (t.to_f - last_lvl_ts.to_f) val_dur = "%9.5f" % (t.to_f - last_val_ts.to_f) last_log_ts = t case tag when /LVL/i last_lvl_ts = t dur = lvl_dur when /PASS|FAIL/i last_val_ts = t dur = val_dur else dur = log_dur end [dur, log_dur, lvl_dur, val_dur] end |
#debug_to_log(message, wai_lvl = 3) Also known as: debug_tolog
This method returns an undefined value.
168 169 170 171 172 173 174 |
# File 'lib/awetestlib/logging.rb', line 168 def debug_to_log(, wai_lvl = 3) << "\n#{get_debug_list}" if $debug scr_lvl = first_script_index lvl = scr_lvl > 0 ? scr_lvl : wai_lvl (DEBUG, "#{}", nil, where_am_i?(lvl)) true end |
#debug_to_report(message, wai_lvl = 4)
This method returns an undefined value.
252 253 254 255 256 257 |
# File 'lib/awetestlib/logging.rb', line 252 def debug_to_report(, wai_lvl = 4) scr_lvl = first_script_index lvl = scr_lvl > 0 ? scr_lvl : wai_lvl mark_test_level("(DEBUG): ", 0, "#{}", 1, lvl + 1) true end |
#error_to_log(message, wai_lvl = 3, exception = nil) Also known as: error_tolog
Do not use for failed validations. Use only for serious error conditions.
This method returns an undefined value.
181 182 183 184 185 186 |
# File 'lib/awetestlib/logging.rb', line 181 def error_to_log(, wai_lvl = 3, exception = nil) scr_lvl = first_script_index lvl = scr_lvl > 0 ? scr_lvl : wai_lvl (ERROR, , nil, where_am_i?(lvl), exception) false end |
#failed_to_log(message, wai_lvl = 3, exception = nil) Also known as: validate_failed_tolog, validate_failed_to_log, failed_tolog, fail_tolog, fail_to_log
This method returns an undefined value.
210 211 212 213 214 215 216 217 218 |
# File 'lib/awetestlib/logging.rb', line 210 def failed_to_log(, wai_lvl = 3, exception = nil) << " \n#{get_debug_list}" if $debug @my_failed_count += 1 if @my_failed_count parse_error_references(, true) scr_lvl = first_script_index lvl = scr_lvl > 0 ? scr_lvl : wai_lvl (WARN, "#{}", FAIL, where_am_i?(lvl), exception) false end |
#fatal_to_log(message, wai_lvl = 3, exception = nil) Also known as: fatal_tolog
This method returns an undefined value.
228 229 230 231 232 233 234 235 236 237 |
# File 'lib/awetestlib/logging.rb', line 228 def fatal_to_log(, wai_lvl = 3, exception = nil) << " #{get_debug_list}" @my_failed_count += 1 if @my_failed_count parse_error_references(, true) debug_to_report("#{__method__}:\n#{dump_caller(nil)}") scr_lvl = first_script_index lvl = scr_lvl > 0 ? scr_lvl : wai_lvl (FATAL, "#{} '#{$!}'", FAIL, where_am_i?(lvl), exception) false end |
#first_script_index(script = @myName) ⇒ Object
418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'lib/awetestlib/logging.rb', line 418 def first_script_index(script = @myName) here = 0 call_list = get_call_list_new debug_to_log(DEBUG, with_caller("=== #{__LINE__}\n#{call_list.to_yaml}\n===")) if $debug call_list.each_index do |x| a_caller = call_list[x].to_s a_caller =~ /([\(\)\w_\_\-\.]+\:\d+\:?.*?)$/ caller = $1 if caller =~ /#{script}/ here = x break end end here rescue failed_to_log(unable_to) end |
#info_to_log(message, wai_lvl = 1) Also known as: message_tolog, message_to_log, info_tolog
This method returns an undefined value.
158 159 160 |
# File 'lib/awetestlib/logging.rb', line 158 def info_to_log(, wai_lvl = 1) (INFO, , '', where_am_i?(wai_lvl)) end |
#mark_test_level(message = '', lvl = nil, desc = '', caller = 1, wai_lvl = 4, trc = $debug) ⇒ Boolean Also known as: mark_testlevel
Write a status message to the log and report indicating location or activity in the script. mark_test_level automatically determines the call hierarchy level of the calling method within the script and project utility methods. The top level method of the script is always level 1. The method also prefixes the calling method name (titleized) to the message to be placed in the log. calling method name. attached. Any other integer is ignored in favor of the calculated level
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/awetestlib/logging.rb', line 127 def mark_test_level( = '', lvl = nil, desc = '', caller = 1, wai_lvl = 4, trc = $debug) strg = '' list = nil call_arr = get_call_array debug_to_log("#{call_arr.to_yaml}") if trc call_script, call_line, call_meth = parse_caller(call_arr[caller]) if not lvl or lvl > 1 lvl, list = get_test_level strg << "#{call_meth.titleize}: " end if lvl == 0 parse_error_references() end strg << "#{}" if .length > 0 strg << " (#{desc})" if desc.length > 0 strg << " [#{call_line}]" if trc strg << "\n#{list.to_yaml}" if list and trc (INFO, strg, lvl, where_am_i?(wai_lvl)) true rescue failed_to_log(unable_to) end |
#message_to_report(message, wai_lvl = 4) ⇒ Boolean
Returns Always returns true.
243 244 245 246 247 248 |
# File 'lib/awetestlib/logging.rb', line 243 def (, wai_lvl = 4) scr_lvl = first_script_index lvl = scr_lvl > 0 ? scr_lvl : wai_lvl mark_test_level(, 0, '', 1, lvl + 1) true end |
#passed_to_log(message, wai_lvl = 3, dbg = false) Also known as: validate_passed_tolog, validate_passed_to_log, passed_tolog, pass_tolog, pass_to_log
This method returns an undefined value.
192 193 194 195 196 197 198 199 200 |
# File 'lib/awetestlib/logging.rb', line 192 def passed_to_log(, wai_lvl = 3, dbg = false) << " \n#{get_debug_list}" if $debug @my_passed_count += 1 if @my_passed_count parse_error_references() scr_lvl = first_script_index lvl = scr_lvl > 0 ? scr_lvl : wai_lvl (INFO, "#{}", PASS, where_am_i?(lvl)) true end |
#where_am_i?(index = 2) ⇒ Boolean
403 404 405 406 407 408 409 410 411 412 413 414 415 416 |
# File 'lib/awetestlib/logging.rb', line 403 def where_am_i?(index = 2) index = index ? index : 2 calls = get_call_list_new (DEBUG, "=== #{__LINE__}\n#{calls.to_yaml}\n===") if $debug if calls[index] where = calls[index].dup.to_s here = where.gsub(/^\[/, '').gsub(/\]\s*$/, '') else here = 'unknown' end here rescue failed_to_log(unable_to) end |
#with_caller(message = '', *strings) ⇒ Object Also known as: message_with_caller, msg_with_caller
390 391 392 393 394 395 396 397 398 |
# File 'lib/awetestlib/logging.rb', line 390 def with_caller( = '', *strings) call_arr = get_call_array call_script, call_line, call_meth = parse_caller(call_arr[1]) strg = "#{call_meth.titleize}" strg << ':' # if strings.size > 0 strg << ' ' strg << (, *strings) strg end |