[rb] Fix Logger#output= on Ruby < 2.3
@@ -45,16 +45,16 @@ module Selenium
:level
def initialize
- @logger = ::Logger.new($stdout)
- @logger.progname = 'Selenium'
- @logger.level = ($DEBUG ? DEBUG : WARN)
- @logger.formatter = proc do |severity, time, progname, msg|
- "#{time.strftime('%F %T')} #{severity} #{progname} #{msg}\n"
- end
+ @logger = create_logger($stdout)
end
def output=(io)
+ # `Logger#reopen` was added in Ruby 2.3
+ if @logger.respond_to?(:reopen)
@logger.reopen(io)
+ else
+ @logger = create_logger(io)
+ end
end
#
@@ -66,8 +66,7 @@ module Selenium
if severity.is_a?(Integer)
@logger.level = severity
else
- _severity = severity.to_s.downcase
- case _severity
+ case severity.to_s.downcase
when 'debug'.freeze
@logger.level = DEBUG
when 'info'.freeze
@@ -104,6 +103,19 @@ module Selenium
File.new(Platform.null_device, 'w')
end
end
+
+ private
+
+ def create_logger(output)
+ logger = ::Logger.new(output)
+ logger.progname = 'Selenium'
+ logger.level = ($DEBUG ? DEBUG : WARN)
+ logger.formatter = proc do |severity, time, progname, msg|
+ "#{time.strftime('%F %T')} #{severity} #{progname} #{msg}\n"
+ end
+
+ logger
+ end
end # Logger
end # WebDriver
end # Selenium
