Class: Webdrone::Logs
- Inherits:
-
Object
- Object
- Webdrone::Logs
- Defined in:
- lib/webdrone/logg.rb
Instance Attribute Summary collapse
-
#a0 ⇒ Object
readonly
Returns the value of attribute a0.
Instance Method Summary collapse
-
#initialize(a0) ⇒ Logs
constructor
A new instance of Logs.
- #setup_format ⇒ Object
- #setup_trace ⇒ Object
- #trace(ini, fin, from, lineno, base, method_name, args, result, exception, screenshot) ⇒ Object
- #with_group(name, abort_error: false) ⇒ Object
Constructor Details
#initialize(a0) ⇒ Logs
Returns a new instance of Logs.
91 92 93 94 95 96 |
# File 'lib/webdrone/logg.rb', line 91 def initialize(a0) @a0 = a0 @group_trace_count = [] setup_format setup_trace end |
Instance Attribute Details
#a0 ⇒ Object (readonly)
Returns the value of attribute a0.
89 90 91 |
# File 'lib/webdrone/logg.rb', line 89 def a0 @a0 end |
Instance Method Details
#setup_format ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/webdrone/logg.rb', line 138 def setup_format begin cols, _line = HighLine.default_instance.terminal.terminal_size rescue StandardError => error puts "ignoring error: #{error}" end cols ||= 120 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_trace ⇒ Object
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/webdrone/logg.rb', line 155 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] browser_platform = a0.driver.capabilities[:platform] webdrone_version = Webdrone::VERSION webdrone_platform = "#{RUBY_ENGINE}-#{RUBY_VERSION} #{RUBY_PLATFORM}" csv << %w.OS ARCH HOSTNAME BROWSER\ NAME BROWSER\ VERSION BROWSER\ PLATFORM WEBDRONE\ VERSION WEBDRONE\ PLATFORM. csv << [os, bits, hostname, browser_name, browser_version, browser_platform, webdrone_version, webdrone_platform] 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
98 99 100 101 102 103 104 105 |
# File 'lib/webdrone/logg.rb', line 98 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) unless a0.conf.logger.to_s == 'quiet' 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 @group_trace_count = @group_trace_count.map { |x| x + 1 } end |
#with_group(name, abort_error: false) ⇒ Object
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 |
# File 'lib/webdrone/logg.rb', line 107 def with_group(name, abort_error: false) ini = Time.new caller_location = Kernel.caller_locations[0] cl_path = caller_location.path cl_line = caller_location.lineno result = {} @group_trace_count << 0 exception = nil begin yield rescue StandardError => e exception = e bindings = Kernel.binding.callers bindings[0..].each do |binding| location = { path: binding.source_location[0], lineno: binding.source_location[1] } next unless Gem.path.none? { |path| location[:path].include? path } result[:exception] = {} result[:exception][:line] = location[:lineno] result[:exception][:path] = location[:path] break end end result[:trace_count] = @group_trace_count.pop fin = Time.new trace(ini, fin, cl_path, cl_line, Logs, :with_group, [name, { abort_error: abort_error }], result, exception, nil) puts "abort_error: #{abort_error} exception: #{exception}" exit if abort_error == true && exception end |