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

Instance Method Summary collapse

Class Method Details

.included(mod) ⇒ Object

Deprecated.


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.

Parameters:

  • message (String)

    The text to place in the log and report



168
169
170
171
172
173
174
# File 'lib/awetestlib/logging.rb', line 168

def debug_to_log(message, wai_lvl = 3)
  message << "\n#{get_debug_list}" if $debug
  scr_lvl = first_script_index
  lvl     = scr_lvl > 0 ? scr_lvl : wai_lvl
  log_message(DEBUG, "#{message}", nil, where_am_i?(lvl))
  true
end

#debug_to_report(message, wai_lvl = 4)

This method returns an undefined value.

Parameters:

  • message (String)

    The text to place in the log and report



252
253
254
255
256
257
# File 'lib/awetestlib/logging.rb', line 252

def debug_to_report(message, wai_lvl = 4)
  scr_lvl = first_script_index
  lvl     = scr_lvl > 0 ? scr_lvl : wai_lvl
  mark_test_level("(DEBUG): ", 0, "#{message}", 1, lvl + 1)
  true
end

#error_to_log(message, wai_lvl = 3, exception = nil) Also known as: error_tolog

Note:

Do not use for failed validations. Use only for serious error conditions.

This method returns an undefined value.

Parameters:

  • message (String)

    The text to place in the log and report



181
182
183
184
185
186
# File 'lib/awetestlib/logging.rb', line 181

def error_to_log(message, wai_lvl = 3, exception = nil)
  scr_lvl = first_script_index
  lvl     = scr_lvl > 0 ? scr_lvl : wai_lvl
  log_message(ERROR, message, 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.

Parameters:

  • message (String)

    The text to place in the log and report



210
211
212
213
214
215
216
217
218
# File 'lib/awetestlib/logging.rb', line 210

def failed_to_log(message, wai_lvl = 3, exception = nil)
  message << " \n#{get_debug_list}" if $debug
  @my_failed_count += 1 if @my_failed_count
  parse_error_references(message, true)
  scr_lvl = first_script_index
  lvl     = scr_lvl > 0 ? scr_lvl : wai_lvl
  log_message(WARN, "#{message}", 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.

Parameters:

  • message (String)

    The text to place in the log and report



228
229
230
231
232
233
234
235
236
237
# File 'lib/awetestlib/logging.rb', line 228

def fatal_to_log(message, wai_lvl = 3, exception = nil)
  message << " #{get_debug_list}"
  @my_failed_count += 1 if @my_failed_count
  parse_error_references(message, true)
  debug_to_report("#{__method__}:\n#{dump_caller(nil)}")
  scr_lvl = first_script_index
  lvl     = scr_lvl > 0 ? scr_lvl : wai_lvl
  log_message(FATAL, "#{message} '#{$!}'", 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.

Parameters:

  • message (String)

    The text to place in the log



158
159
160
# File 'lib/awetestlib/logging.rb', line 158

def info_to_log(message, wai_lvl = 1)
  log_message(INFO, message, '', 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

Parameters:

  • message (String) (defaults to: '')

    The text to place in the log and report after the titleized

  • lvl (Fixnum) (defaults to: nil)

    ‘0’ forces a message to the report without a specific level

  • desc (String) (defaults to: '')

    Any additional information to add to the message.

  • trc (Boolean) (defaults to: $debug)

    When set to true adds a trace to the message.

Returns:

  • (Boolean)

    Always returns true



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(message = '', 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(message)
  end
  strg << "#{message}" if message.length > 0
  strg << " (#{desc})" if desc.length > 0
  strg << " [#{call_line}]" if trc
  strg << "\n#{list.to_yaml}" if list and trc

  log_message(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.

Parameters:

  • message (String)

    The text to place in the log and report

Returns:

  • (Boolean)

    Always returns true



243
244
245
246
247
248
# File 'lib/awetestlib/logging.rb', line 243

def message_to_report(message, wai_lvl = 4)
  scr_lvl = first_script_index
  lvl     = scr_lvl > 0 ? scr_lvl : wai_lvl
  mark_test_level(message, 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.

Parameters:

  • message (String)

    The text to place in the log and report



192
193
194
195
196
197
198
199
200
# File 'lib/awetestlib/logging.rb', line 192

def passed_to_log(message, wai_lvl = 3, dbg = false)
  message << " \n#{get_debug_list}" if $debug
  @my_passed_count += 1 if @my_passed_count
  parse_error_references(message)
  scr_lvl = first_script_index
  lvl     = scr_lvl > 0 ? scr_lvl : wai_lvl
  log_message(INFO, "#{message}", PASS, where_am_i?(lvl))
  true
end

#where_am_i?(index = 2) ⇒ Boolean

Returns:

  • (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
  log_message(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(message = '', *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 << build_message(message, *strings)
  strg
end