Skip to content

Commit 1673a69

Browse files
committed
Use the logger object for outputting debug information
1 parent 4573473 commit 1673a69

File tree

3 files changed

+31
-19
lines changed

3 files changed

+31
-19
lines changed

lib/appium_lib/common/patch.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def raw_execute(command, opts = {}, command_hash = nil)
9090
path_match = path.match /.*\h{8}-?\h{4}-?\h{4}-?\h{4}-?\h{12}/
9191
path_str = path.sub(path_match[0], '') unless path_match.nil?
9292

93-
puts "#{verb} #{path_str}"
93+
Appium::Logger.info "#{verb} #{path_str}"
9494

9595
# must check to see if command_hash is a hash. sometimes it's not.
9696
if command_hash.is_a?(Hash) && !command_hash.empty?
@@ -103,18 +103,18 @@ def raw_execute(command, opts = {}, command_hash = nil)
103103
print_command[:value] = value.length == 1 ? value[0] : value
104104

105105
# avoid backslash escape quotes in strings. "\"a\"" => "a"
106-
puts print_command.ai.gsub('\"', '"')
106+
Appium::Logger.info print_command.ai.gsub('\"', '"')
107107
else
108-
ap print_command
108+
Appium::Logger.ap_info print_command
109109
end
110110
else # non-standard command hash
111111
# It's important to output this for debugging problems.
112112
# for example invalid JSON will not be a Hash
113-
ap command_hash if command_hash
113+
Appium::Logger.ap_info command_hash if command_hash
114114
end
115115
delay = $driver.global_webdriver_http_sleep
116116
sleep delay if !delay.nil? && delay > 0
117-
# puts "verb: #{verb}, path #{path}, command_hash #{command_hash.to_json}"
117+
# Appium::Logger.info "verb: #{verb}, path #{path}, command_hash #{command_hash.to_json}"
118118
http.call verb, path, command_hash
119119
end # def
120120
end # class

lib/appium_lib/driver.rb

+11-11
Original file line numberDiff line numberDiff line change
@@ -76,20 +76,20 @@ def self.load_appium_txt opts={}
7676

7777
parent_dir = File.dirname file
7878
toml = File.expand_path File.join parent_dir, 'appium.txt'
79-
puts "appium.txt path: #{toml}" if verbose
79+
Appium::Logger.info "appium.txt path: #{toml}" if verbose
8080

8181
toml_exists = File.exists? toml
82-
puts "Exists? #{toml_exists}" if verbose
82+
Appium::Logger.info "Exists? #{toml_exists}" if verbose
8383

8484
raise "toml doesn't exist #{toml}" unless toml_exists
8585
require 'toml'
86-
puts "Loading #{toml}" if verbose
86+
Appium::Logger.info "Loading #{toml}" if verbose
8787

8888
data = File.read toml
8989
data = TOML::Parser.new(data).parsed
9090
# TOML creates string keys. must symbolize
9191
data = Appium::symbolize_keys data
92-
ap data unless data.empty? if verbose
92+
Appium::Logger.ap_info data unless data.empty? if verbose
9393

9494
if data && data[:caps] && data[:caps][:app] && !data[:caps][:app].empty?
9595
data[:caps][:app] = Appium::Driver.absolute_app_path data
@@ -319,9 +319,9 @@ def initialize opts={}
319319
@appium_debug = appium_lib_opts.fetch :debug, !!defined?(Pry)
320320

321321
if @appium_debug
322-
ap opts unless opts.empty?
323-
puts "Debug is: #{@appium_debug}"
324-
puts "Device is: #{@appium_device}"
322+
Appium::Logger.ap_debug opts unless opts.empty?
323+
Appium::Logger.debug "Debug is: #{@appium_debug}"
324+
Appium::Logger.debug "Device is: #{@appium_device}"
325325
patch_webdriver_bridge
326326
end
327327

@@ -512,14 +512,14 @@ def no_wait
512512
# @return [void]
513513
def set_wait timeout=nil
514514
if timeout.nil?
515-
# puts "timeout = @default_wait = @last_wait"
516-
# puts "timeout = @default_wait = #{@last_waits}"
515+
# Appium::Logger.info "timeout = @default_wait = @last_wait"
516+
# Appium::Logger.info "timeout = @default_wait = #{@last_waits}"
517517
timeout = @default_wait = @last_waits.first
518518
else
519519
@default_wait = timeout
520-
# puts "last waits before: #{@last_waits}"
520+
# Appium::Logger.info "last waits before: #{@last_waits}"
521521
@last_waits = [@last_waits.last, @default_wait]
522-
# puts "last waits after: #{@last_waits}"
522+
# Appium::Logger.info "last waits after: #{@last_waits}"
523523
end
524524

525525
@driver.manage.timeouts.implicit_wait = timeout

lib/appium_lib/logger.rb

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
1+
require 'logger'
2+
13
module Appium
24
module Logger
35
class << self
46
extend Forwardable
5-
def_delegators :@logger, :warn, :error, :info
7+
def_delegators :logger, :ap, :fatal, :error, :warn, :info, :debug, :level, :level=, :formatter, :formatter=
8+
9+
[:fatal, :error, :warn, :info, :debug].each do |level|
10+
define_method("ap_#{level}") {|obj| logger.ap(obj, level) }
11+
end
612

7-
# @private
13+
private
14+
815
def logger
9-
@logger ||= Logger.new
16+
@logger ||= begin
17+
logger = ::Logger.new($stdout)
18+
logger.level = ::Logger::WARN
19+
logger.formatter = proc { |severity, datetime, progname, msg| "#{msg}\n" } # do no special formatting
20+
logger
21+
end
1022
end
1123
end # class << self
1224
end # module Logger

0 commit comments

Comments
 (0)