Class: Selenium::WebDriver::Logger

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
build/rb/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

#initialize(progname = 'Selenium') ⇒ Logger

Returns a new instance of Logger.

Parameters:

  • progname (String) (defaults to: 'Selenium')

    Allow child projects to use Selenium's Logger pattern



51
52
53
54
# File 'build/rb/lib/selenium/webdriver/common/logger.rb', line 51

def initialize(progname = 'Selenium')
  @logger = create_logger(progname)
  @ignored = []
end

Instance Method Details

#deprecate(old, new = nil, id: []) { ... } ⇒ Object

Marks code as deprecated with/without replacement.

Parameters:

  • old (String)
  • new (String, nil) (defaults to: nil)
  • id (Symbol, Array<Sybmol>) (defaults to: [])

Yields:

  • appends additional message to end of provided template



114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'build/rb/lib/selenium/webdriver/common/logger.rb', line 114

def deprecate(old, new = nil, id: [], &block)
  id = Array(id)
  return if @ignored.include?(:deprecations) || (@ignored & id).any?

  ids = id.empty? ? '' : "[#{id.map(&:inspect).join(', ')}] "

  message = +"[DEPRECATION] #{ids}#{old} is deprecated"
  message << if new
               ". Use #{new} instead."
             else
               ' and will be removed in a future release.'
             end
  warn message, &block
end

#ignore(id) ⇒ Object

Will not log the provided ID.

Parameters:

  • id (Array, Symbol)


85
86
87
# File 'build/rb/lib/selenium/webdriver/common/logger.rb', line 85

def ignore(id)
  Array(id).each { |ignore| @ignored << ignore }
end

#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.



76
77
78
# File 'build/rb/lib/selenium/webdriver/common/logger.rb', line 76

def io
  @logger.instance_variable_get(:@logdev).dev
end

#output=(io) ⇒ Object

Changes logger output to a new IO.

Parameters:

  • io (String)


61
62
63
# File 'build/rb/lib/selenium/webdriver/common/logger.rb', line 61

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

#warn(message, id: []) { ... } ⇒ Object

Overrides default #warn to skip ignored messages by provided id

Parameters:

  • message (String)
  • id (Symbol, Array<Sybmol>) (defaults to: [])

Yields:

  • see #deprecate



96
97
98
99
100
101
102
103
104
# File 'build/rb/lib/selenium/webdriver/common/logger.rb', line 96

def warn(message, id: [])
  id = Array(id)
  return if (@ignored & id).any?

  msg = id.empty? ? message : "[#{id.map(&:inspect).join(', ')}] #{message} "
  msg += " #{yield}" if block_given?

  @logger.warn { msg }
end