class Selenium::WebDriver::Logger
Selenium::WebDriver.logger.warn(‘This is warning message’)
Selenium::WebDriver.logger.info(‘This is info message’)
@example Use logger manually
Selenium::WebDriver.logger.output = ‘selenium.log’
@example Log to file
Selenium::WebDriver.logger.level = :debug
@example Enable full logging
def allow(ids)
-
ids
(Array, Symbol
) --
def allow(ids) @allowed += Array(ids).flatten end
def create_logger(name, level:)
def create_logger(name, level:) logger = ::Logger.new($stdout) logger.progname = name logger.level = level logger.formatter = proc do |severity, time, progname, msg| "#{time.strftime('%F %T')} #{severity} #{progname} #{msg}\n" end logger end
def debug(message, id: [], &block)
- Yield: - see #deprecate
Parameters:
-
id
(Symbol, Array
) -- -
message
(String
) --
def debug(message, id: [], &block) discard_or_log(:debug, message, id, &block) end
def deprecate(old, new = nil, id: [], reference: '', &block)
- Yield: - appends additional message to end of provided template
Parameters:
-
reference
(String
) -- -
id
(Symbol, Array
) -- -
new
(String, nil
) -- -
old
(String
) --
def deprecate(old, new = nil, id: [], reference: '', &block) id = Array(id) return if @ignored.include?(:deprecations) id << :deprecations if @allowed.include?(:deprecations) message = +"[DEPRECATION] #{old} is deprecated" message << if new ". Use #{new} instead." else ' and will be removed in a future release.' end message << " See explanation for this deprecation: #{reference}." unless reference.empty? discard_or_log(:warn, message, id, &block) end
def discard_or_log(level, message, id)
def discard_or_log(level, message, id) id = Array(id) return if (@ignored & id).any? 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? ? message : "[#{id.map(&:inspect).join(', ')}] #{message} " msg += " #{yield}" if block_given? @logger.send(level) { msg } end
def error(message, id: [], &block)
- Yield: - see #deprecate
Parameters:
-
id
(Symbol, Array
) -- -
message
(String
) --
def error(message, id: [], &block) discard_or_log(:error, message, id, &block) end
def ignore(*ids)
-
ids
(Array, Symbol
) --
def ignore(*ids) @ignored += Array(ids).flatten end
def info(message, id: [], &block)
- Yield: - see #deprecate
Parameters:
-
id
(Symbol, Array
) -- -
message
(String
) --
def info(message, id: [], &block) discard_or_log(:info, message, id, &block) end
def initialize(progname = 'Selenium', default_level: nil, ignored: nil, allowed: nil)
-
progname
(String
) -- Allow child projects to use Selenium's Logger pattern
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
def io
- Api: - private
def io @logger.instance_variable_get(:@logdev).dev end
def level=(level)
def level=(level) if level == :info && @logger.level == :info info(':info is now the default log level, to see additional logging, set log level to :debug') end @logger.level = level end
def output=(io)
-
io
(String
) --
def output=(io) @logger.reopen(io) end
def warn(message, id: [], &block)
- Yield: - see #deprecate
Parameters:
-
id
(Symbol, Array
) -- -
message
(String
) --
def warn(message, id: [], &block) discard_or_log(:warn, message, id, &block) end