class Selenium::WebDriver::Logger

@example Enable full logging

Selenium::WebDriver.logger.level = :debug

@example Log to file

Selenium::WebDriver.logger.output = 'selenium.log'

@example Use logger manually

Selenium::WebDriver.logger.info('This is info message')
Selenium::WebDriver.logger.warn('This is warning message')

Public Class Methods

new() click to toggle source
# File lib/selenium/webdriver/common/logger.rb, line 48
def initialize
  @logger = create_logger($stdout)
end

Public Instance Methods

deprecate(old, new = nil) click to toggle source

Marks code as deprecated with/without replacement.

@param [String] old @param [String, nil] new

# File lib/selenium/webdriver/common/logger.rb, line 82
def deprecate(old, new = nil)
  message = +"[DEPRECATION] #{old} is deprecated"
  message << if new
               ". Use #{new} instead."
             else
               ' and will be removed in the next releases.'
             end

  warn message
end
io() click to toggle source

Returns IO object used by logger internally.

Normally, we would have never needed it, but we want to use it as IO object for all child processes to ensure their output is redirected there.

It is only used in debug level, in other cases output is suppressed.

@api private

# File lib/selenium/webdriver/common/logger.rb, line 72
def io
  @logger.instance_variable_get(:@logdev).dev
end
output=(io) click to toggle source

Changes logger output to a new IO.

@param [String] io

# File lib/selenium/webdriver/common/logger.rb, line 57
def output=(io)
  @logger.reopen(io)
end

Private Instance Methods

create_logger(output) click to toggle source
# File lib/selenium/webdriver/common/logger.rb, line 95
def create_logger(output)
  logger = ::Logger.new(output)
  logger.progname = 'Selenium'
  logger.level = default_level
  logger.formatter = proc do |severity, time, progname, msg|
    "#{time.strftime('%F %T')} #{severity} #{progname} #{msg}\n"
  end

  logger
end
default_level() click to toggle source
# File lib/selenium/webdriver/common/logger.rb, line 106
def default_level
  if $DEBUG || ENV.key?('DEBUG')
    :debug
  else
    :warn
  end
end