Module: Wmap::Utils::Logger

Extended by:
Logger
Included in:
Wmap::Utils, Logger
Defined in:
lib/wmap/utils/logger.rb

Overview

Module to log debugging and other messages

Instance Method Summary collapse

Instance Method Details

#wlog(obj, agent, file) ⇒ Object

Append information into the log file for the trouble-shooting purpose



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/wmap/utils/logger.rb', line 16

def wlog (obj, agent, file)
  puts "Writing #{obj} into log file: #{file}" if @verbose
  return false if obj.nil?
  @@f=File.open(file,'a')
  timestamp=Time.now
  case obj
  when Array
    if obj.size >= 0
      @@f.write "#{timestamp}: #{agent}: \n"
      obj.map { |x| @@f.write "  #{x}\n" }
      puts "The list is successfully saved into the log file: #{file} " if @verbose
    end
  when Hash
    if obj.length >= 0
      @@f.write "#{timestamp}: #{agent}: \n"
      obj.each_value { |value| @@f.write "  #{value}\n" }
      puts "The hash is successfully saved into the log file: #{file} " if @verbose
    end
  when String
    @@f.write "#{timestamp}: #{agent}: #{obj}\n"
    puts "The string is successfully saved into the log file: #{file} " if @verbose
  else
    #do nothing
    puts "Un-handled exception on: #{obj}" if @verbose
  end
  @@f.close
  return true
rescue => ee
  puts "Exception on method #{__method__}: #{ee}" if @verbose
  return false
end