diff --git a/rb/lib/selenium/webdriver/common/logger.rb b/rb/lib/selenium/webdriver/common/logger.rb index 9bd01cf5055ca..1c5fee17fe74d 100644 --- a/rb/lib/selenium/webdriver/common/logger.rb +++ b/rb/lib/selenium/webdriver/common/logger.rb @@ -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 @@ -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? diff --git a/rb/spec/unit/selenium/webdriver/common/logger_spec.rb b/rb/spec/unit/selenium/webdriver/common/logger_spec.rb index f65cbd2ea4f50..2b75c5e837f4c 100644 --- a/rb/spec/unit/selenium/webdriver/common/logger_spec.rb +++ b/rb/spec/unit/selenium/webdriver/common/logger_spec.rb @@ -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