Class: Selenium::WebDriver::Logger

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/selenium/webdriver/common/logger.rb

Overview

Examples:

Enable full logging

Selenium::WebDriver.logger.level = :debug

Log to file

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

Use logger manually

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

Instance Method Summary collapse

Constructor Details

#initializeLogger

Returns a new instance of Logger.



46
47
48
49
50
51
52
53
# File 'lib/selenium/webdriver/common/logger.rb', line 46

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
end

Instance Method Details

#ioObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.



70
71
72
73
74
75
76
# File 'lib/selenium/webdriver/common/logger.rb', line 70

def io
  if debug?
    @logger.instance_variable_get(:@logdev).instance_variable_get(:@dev)
  else
    File.new(Platform.null_device, 'w')
  end
end

#output=(io) ⇒ Object



55
56
57
# File 'lib/selenium/webdriver/common/logger.rb', line 55

def output=(io)
  @logger.reopen(io)
end