Class: Selenium::WebDriver::Logger
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Forwardable
|
|
Inherits: | Object |
Defined in: | rb/lib/selenium/webdriver/common/logger.rb |
Overview
Class Method Summary
Instance Attribute Summary
- #level=(level) writeonly
-
#output=(io)
writeonly
Changes logger output to a new IO.
Instance Method Summary
-
#allow(*ids)
Will only log the provided ID.
-
#debug(message, id: [], &block)
Used to supply information of interest for debugging a problem Overrides default #debug to skip ignored messages by provided id.
-
#deprecate(old, new = nil, id: [], reference: '') { ... }
Marks code as deprecated with/without replacement.
-
#error(message, id: [], &block)
Used to supply information that suggests an error occurred.
-
#ignore(*ids)
Will not log the provided ID.
-
#info(message, id: [], &block)
Used to supply information of general interest.
-
#warn(message, id: [], &block)
Used to supply information that suggests action be taken by user.
- #create_logger(name, level:) private
- #discard_or_log(level, message, id) private
-
#io
Internal use only
Internal use only
Returns IO object used by logger internally.
Constructor Details
.new(progname = 'Selenium', default_level: nil, ignored: nil, allowed: nil) ⇒ Logger
# File 'rb/lib/selenium/webdriver/common/logger.rb', line 51
def initialize(progname = 'Selenium', default_level: nil, ignored: nil, allowed: nil) default_level ||= $DEBUG || ENV.key?('DEBUG') ? :debug : :warn @logger = create_logger(progname, level: default_level) @ignored = Array(ignored) @allowed = Array(allowed) @first_warning = false end
Instance Attribute Details
#level=(level) (writeonly)
[ GitHub ]#output=(io) (writeonly)
Changes logger output to a new IO.
Instance Method Details
#allow(*ids)
Will only log the provided ID.
# File 'rb/lib/selenium/webdriver/common/logger.rb', line 106
def allow(*ids) @allowed += Array(ids).flatten end
#create_logger(name, level:) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/logger.rb', line 183
def create_logger(name, level:) logger = ::Logger.new($stderr) logger.progname = name logger.level = level logger.formatter = proc do |severity, time, progname, msg| "#{time.strftime('%F %T')} #{severity} #{progname} #{msg}\n".force_encoding('UTF-8') end logger end
#debug(message, id: [], &block)
Used to supply information of interest for debugging a problem Overrides default #debug
to skip ignored messages by provided id
# File 'rb/lib/selenium/webdriver/common/logger.rb', line 118
def debug(, id: [], &block) discard_or_log(:debug, , id, &block) end
#deprecate(old, new = nil, id: [], reference: '') { ... }
Marks code as deprecated with/without replacement.
# File 'rb/lib/selenium/webdriver/common/logger.rb', line 164
def deprecate(old, new = nil, id: [], reference: '', &block) id = Array(id) return if @ignored.include?(:deprecations) id << :deprecations if @allowed.include?(:deprecations) = "[DEPRECATION] #{old} is deprecated" << if new ". Use #{new} instead." else ' and will be removed in a future release.' end << " See explanation for this deprecation: #{reference}." unless reference.empty? discard_or_log(:warn, , id, &block) end
#discard_or_log(level, message, id) (private)
[ GitHub ]# File 'rb/lib/selenium/webdriver/common/logger.rb', line 194
def discard_or_log(level, , id) id = Array(id) return if @ignored.intersect?(id) return if @allowed.any? && (@allowed & id).none? return if ::Logger::Severity.const_get(level.upcase) < @logger.level unless @first_warning @first_warning = true info("Details on how to use and modify Selenium logger:\n", id: [:logger_info]) do "https://selenium.dev/documentation/webdriver/troubleshooting/logging\n" end end msg = id.empty? ? : "[#{id.map(&:inspect).join(', ')}] #{} " msg += " #{yield}" if block_given? @logger.send(level) { msg } end
#error(message, id: [], &block)
Used to supply information that suggests an error occurred
# File 'rb/lib/selenium/webdriver/common/logger.rb', line 140
def error(, id: [], &block) discard_or_log(:error, , id, &block) end
#ignore(*ids)
Will not log the provided ID.
# File 'rb/lib/selenium/webdriver/common/logger.rb', line 97
def ignore(*ids) @ignored += Array(ids).flatten end
#info(message, id: [], &block)
Used to supply information of general interest
# File 'rb/lib/selenium/webdriver/common/logger.rb', line 129
def info(, id: [], &block) discard_or_log(:info, , id, &block) end
#io
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.
# File 'rb/lib/selenium/webdriver/common/logger.rb', line 88
def io @logger.instance_variable_get(:@logdev).dev end
#warn(message, id: [], &block)
Used to supply information that suggests action be taken by user
# File 'rb/lib/selenium/webdriver/common/logger.rb', line 151
def warn(, id: [], &block) discard_or_log(:warn, , id, &block) end