Class: Webdrone::Logs

Inherits:
Object
  • Object
show all
Defined in:
lib/webdrone/logg.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(a0) ⇒ Logs

Returns a new instance of Logs.



49
50
51
52
53
# File 'lib/webdrone/logg.rb', line 49

def initialize(a0)
  @a0 = a0
  setup_format
  setup_trace
end

Instance Attribute Details

#a0Object

Returns the value of attribute a0.



47
48
49
# File 'lib/webdrone/logg.rb', line 47

def a0
  @a0
end

Instance Method Details

#setup_formatObject



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/webdrone/logg.rb', line 63

def setup_format
  cols, line = HighLine::SystemExtensions.terminal_size
  total = 6 + 15 + 11 + 5
  w = cols - total
  w /= 2
  w1 = w
  w2 = cols - total - w1
  w1 = 20 if w1 < 20
  w2 = 20 if w2 < 20
  @format = "%5.3f %14.14s %10s %#{w1}.#{w1}s => %#{w2}.#{w2}s\n"
end

#setup_traceObject



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/webdrone/logg.rb', line 75

def setup_trace
  @path = File.join(a0.conf.outdir, 'a0_webdrone_trace.csv')
  CSV.open(@path, "a+") do |csv|
    os = "Windows" if OS.windows?
    os = "Linux" if OS.linux?
    os = "OS X" if OS.osx?
    bits = OS.bits
    hostname = Socket.gethostname
    browser_name = a0.driver.capabilities[:browser_name]
    browser_version = a0.driver.capabilities[:version]
    webdrone_version = Webdrone::VERSION

    csv << %w.OS ARCH HOSTNAME BROWSER\ NAME BROWSER\ VERSION WEBDRONE\ VERSION.
    csv << [os, bits, hostname, browser_name, browser_version, webdrone_version]
  end
  CSV.open(@path, "a+") do |csv|
    csv << %w.DATE DUR FROM LINENO MODULE CALL PARAMS RESULT EXCEPTION SCREENSHOT.
  end
end

#trace(ini, fin, from, lineno, base, method_name, args, result, exception, screenshot) ⇒ Object



55
56
57
58
59
60
61
# File 'lib/webdrone/logg.rb', line 55

def trace(ini, fin, from, lineno, base, method_name, args, result, exception, screenshot)
  exception = "#{exception.class}: #{exception}" if exception
  printf @format, (fin-ini), base, method_name, args, (result || exception)
  CSV.open(@path, "a+") do |csv|
    csv << [ini.strftime('%Y-%m-%d %H:%M:%S.%L %z'), (fin-ini), from, lineno, base, method_name, args, result, exception, screenshot]
  end
end