Skip to content

Commit

Permalink
[rb] improve logger logic
Browse files Browse the repository at this point in the history
  • Loading branch information
titusfortner committed Jun 6, 2023
1 parent fb21cac commit 757faf0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
16 changes: 9 additions & 7 deletions rb/lib/selenium/webdriver/common/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,13 +127,6 @@ def debug(message, id: [], &block)
# @yield see #deprecate
#
def info(message, id: [], &block)
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

discard_or_log(:info, message, id, &block)
end

Expand Down Expand Up @@ -203,6 +196,15 @@ def discard_or_log(level, message, 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?

Expand Down
3 changes: 2 additions & 1 deletion rb/spec/unit/selenium/webdriver/common/logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ module WebDriver
end

describe '#info' do
it 'logs info on first info but not second' do
it 'logs info on first displayed logging only' do
logger = described_class.new('Selenium', default_level: :info)

logger.debug('first')
expect { logger.info('first') }.to output(/:logger_info/).to_stdout_from_any_process
expect { logger.info('second') }.not_to output(/:logger_info/).to_stdout_from_any_process
end
Expand Down

0 comments on commit 757faf0

Please sign in to comment.