From 6f37dba4b3b1576f3d8124c64fceb304669d59a2 Mon Sep 17 00:00:00 2001 From: titusfortner Date: Mon, 11 Dec 2023 10:20:01 -0600 Subject: [PATCH] [rb] logger defaults output to stderr instead of stdout --- rb/lib/selenium/webdriver/common/logger.rb | 2 +- rb/spec/rspec_matchers.rb | 2 +- rb/spec/unit/selenium/devtools_spec.rb | 2 +- .../selenium/webdriver/common/logger_spec.rb | 64 +++++++++---------- 4 files changed, 35 insertions(+), 35 deletions(-) diff --git a/rb/lib/selenium/webdriver/common/logger.rb b/rb/lib/selenium/webdriver/common/logger.rb index f921d3c53cdeb..da172c8eb4918 100644 --- a/rb/lib/selenium/webdriver/common/logger.rb +++ b/rb/lib/selenium/webdriver/common/logger.rb @@ -181,7 +181,7 @@ def deprecate(old, new = nil, id: [], reference: '', &block) private def create_logger(name, level:) - logger = ::Logger.new($stdout) + logger = ::Logger.new($stderr) logger.progname = name logger.level = level logger.formatter = proc do |severity, time, progname, msg| diff --git a/rb/spec/rspec_matchers.rb b/rb/spec/rspec_matchers.rb index 8858ee15e33d8..88ba20289cd8b 100644 --- a/rb/spec/rspec_matchers.rb +++ b/rb/spec/rspec_matchers.rb @@ -22,7 +22,7 @@ LEVELS.each do |level| RSpec::Matchers.define "have_#{level}" do |entry| match do |actual| - # Suppresses logging output to stdout while ensuring that it is still happening + # Suppresses logging output to stderr while ensuring that it is still happening default_output = Selenium::WebDriver.logger.io io = StringIO.new Selenium::WebDriver.logger.output = io diff --git a/rb/spec/unit/selenium/devtools_spec.rb b/rb/spec/unit/selenium/devtools_spec.rb index af15fd438e27c..077bdb1d4ae86 100644 --- a/rb/spec/unit/selenium/devtools_spec.rb +++ b/rb/spec/unit/selenium/devtools_spec.rb @@ -38,7 +38,7 @@ module Selenium it 'can fall back to an older devtools if necessary' do msg1 = /Could not load selenium-devtools v#{version}. Trying older versions/ msg2 = /Using selenium-devtools version v#{current_version}, some features may not work as expected/ - expect { described_class.load_version }.to output(match(msg1).and(match(msg2))).to_stdout_from_any_process + expect { described_class.load_version }.to output(match(msg1).and(match(msg2))).to_stderr_from_any_process end end end diff --git a/rb/spec/unit/selenium/webdriver/common/logger_spec.rb b/rb/spec/unit/selenium/webdriver/common/logger_spec.rb index 2b75c5e837f4c..ba551eb500d81 100644 --- a/rb/spec/unit/selenium/webdriver/common/logger_spec.rb +++ b/rb/spec/unit/selenium/webdriver/common/logger_spec.rb @@ -35,7 +35,7 @@ module WebDriver it 'allows creating a logger with a different progname' do other_logger = described_class.new('NotSelenium') msg = /WARN NotSelenium message/ - expect { other_logger.warn('message') }.to output(msg).to_stdout_from_any_process + expect { other_logger.warn('message') }.to output(msg).to_stderr_from_any_process end it 'does not log info from constructor' do @@ -72,8 +72,8 @@ module WebDriver end describe '#output' do - it 'outputs to stdout by default' do - expect { logger.warn('message') }.to output(/WARN Selenium message/).to_stdout_from_any_process + it 'outputs to stderr by default' do + expect { logger.warn('message') }.to output(/WARN Selenium message/).to_stderr_from_any_process end it 'allows output to file' do @@ -90,17 +90,17 @@ module WebDriver before { logger.level = :debug } it 'logs message' do - expect { logger.debug 'String Value' }.to output(/DEBUG Selenium String Value/).to_stdout_from_any_process + expect { logger.debug 'String Value' }.to output(/DEBUG Selenium String Value/).to_stderr_from_any_process end it 'logs single id when set' do msg = /DEBUG Selenium \[:foo\] debug message/ - expect { logger.debug('debug message', id: :foo) }.to output(msg).to_stdout_from_any_process + expect { logger.debug('debug message', id: :foo) }.to output(msg).to_stderr_from_any_process end it 'logs multiple ids when set' do msg = /DEBUG Selenium \[:foo, :bar\] debug message/ - expect { logger.debug('debug message', id: %i[foo bar]) }.to output(msg).to_stdout_from_any_process + expect { logger.debug('debug message', id: %i[foo bar]) }.to output(msg).to_stderr_from_any_process end end @@ -109,96 +109,96 @@ module WebDriver 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 + expect { logger.info('first') }.to output(/:logger_info/).to_stderr_from_any_process + expect { logger.info('second') }.not_to output(/:logger_info/).to_stderr_from_any_process end it 'logs message' do - expect { logger.info 'String Value' }.to output(/INFO Selenium String Value/).to_stdout_from_any_process + expect { logger.info 'String Value' }.to output(/INFO Selenium String Value/).to_stderr_from_any_process end it 'logs single id when set' do msg = /INFO Selenium \[:foo\] info message/ - expect { logger.info('info message', id: :foo) }.to output(msg).to_stdout_from_any_process + expect { logger.info('info message', id: :foo) }.to output(msg).to_stderr_from_any_process end it 'logs multiple ids when set' do msg = /INFO Selenium \[:foo, :bar\] info message/ - expect { logger.info('info message', id: %i[foo bar]) }.to output(msg).to_stdout_from_any_process + expect { logger.info('info message', id: %i[foo bar]) }.to output(msg).to_stderr_from_any_process end end describe '#warn' do it 'logs message' do - expect { logger.warn 'String Value' }.to output(/WARN Selenium String Value/).to_stdout_from_any_process + expect { logger.warn 'String Value' }.to output(/WARN Selenium String Value/).to_stderr_from_any_process end it 'logs single id when set' do msg = /WARN Selenium \[:foo\] warning message/ - expect { logger.warn('warning message', id: :foo) }.to output(msg).to_stdout_from_any_process + expect { logger.warn('warning message', id: :foo) }.to output(msg).to_stderr_from_any_process end it 'logs multiple ids when set' do msg = /WARN Selenium \[:foo, :bar\] warning message/ - expect { logger.warn('warning message', id: %i[foo bar]) }.to output(msg).to_stdout_from_any_process + expect { logger.warn('warning message', id: %i[foo bar]) }.to output(msg).to_stderr_from_any_process end end describe '#deprecate' do it 'allows to deprecate functionality with replacement' do message = /WARN Selenium \[DEPRECATION\] #old is deprecated\. Use #new instead\./ - expect { logger.deprecate('#old', '#new') }.to output(message).to_stdout_from_any_process + expect { logger.deprecate('#old', '#new') }.to output(message).to_stderr_from_any_process end it 'allows to deprecate functionality without replacement' do message = /WARN Selenium \[DEPRECATION\] #old is deprecated and will be removed in a future release\./ - expect { logger.deprecate('#old') }.to output(message).to_stdout_from_any_process + expect { logger.deprecate('#old') }.to output(message).to_stderr_from_any_process end it 'allows to deprecate functionality with a reference message' do ref_url = 'https://selenium.dev' warn_msg = 'WARN Selenium \[DEPRECATION\] #old is deprecated\. Use #new instead\.' message = /#{warn_msg} See explanation for this deprecation: #{ref_url}/ - expect { logger.deprecate('#old', '#new', reference: ref_url) }.to output(message).to_stdout_from_any_process + expect { logger.deprecate('#old', '#new', reference: ref_url) }.to output(message).to_stderr_from_any_process end it 'appends deprecation message with provided block' do message = /WARN Selenium \[DEPRECATION\] #old is deprecated\. Use #new instead\. More Details\./ - expect { logger.deprecate('#old', '#new') { 'More Details.' } }.to output(message).to_stdout_from_any_process + expect { logger.deprecate('#old', '#new') { 'More Details.' } }.to output(message).to_stderr_from_any_process end it 'logs single id when set' do msg = /WARN Selenium \[:foo\] warning message/ - expect { logger.warn('warning message', id: :foo) }.to output(msg).to_stdout_from_any_process + expect { logger.warn('warning message', id: :foo) }.to output(msg).to_stderr_from_any_process end it 'logs multiple ids when set' do msg = /WARN Selenium \[:foo, :bar\] warning message/ - expect { logger.warn('warning message', id: %i[foo bar]) }.to output(msg).to_stdout_from_any_process + expect { logger.warn('warning message', id: %i[foo bar]) }.to output(msg).to_stderr_from_any_process end end describe '#ignore' do it 'prevents logging when id' do logger.ignore(:foo) - expect { logger.deprecate('#old', '#new', id: :foo) }.not_to output.to_stdout_from_any_process + expect { logger.deprecate('#old', '#new', id: :foo) }.not_to output.to_stderr_from_any_process end it 'prevents logging when ignoring multiple ids' do logger.ignore(:foo) logger.ignore(:bar) - expect { logger.deprecate('#old', '#new', id: :foo) }.not_to output.to_stdout_from_any_process - expect { logger.deprecate('#old', '#new', id: :bar) }.not_to output.to_stdout_from_any_process + expect { logger.deprecate('#old', '#new', id: :foo) }.not_to output.to_stderr_from_any_process + expect { logger.deprecate('#old', '#new', id: :bar) }.not_to output.to_stderr_from_any_process end it 'prevents logging when ignoring Array of ids' do logger.ignore(%i[foo bar]) - expect { logger.deprecate('#old', '#new', id: %i[foo foobar]) }.not_to output.to_stdout_from_any_process + expect { logger.deprecate('#old', '#new', id: %i[foo foobar]) }.not_to output.to_stderr_from_any_process end it 'prevents logging any deprecation when ignoring :deprecations' do logger.ignore(:deprecations) - expect { logger.deprecate('#old', '#new') }.not_to output.to_stdout_from_any_process + expect { logger.deprecate('#old', '#new') }.not_to output.to_stderr_from_any_process end end @@ -206,21 +206,21 @@ module WebDriver it 'logs only allowed ids from method' do logger.allow(:foo) logger.allow(:bar) - expect { logger.deprecate('#old', '#new', id: :foo) }.to output(/foo/).to_stdout_from_any_process - expect { logger.deprecate('#old', '#new', id: :bar) }.to output(/bar/).to_stdout_from_any_process - expect { logger.deprecate('#old', '#new', id: :foobar) }.not_to output.to_stdout_from_any_process + expect { logger.deprecate('#old', '#new', id: :foo) }.to output(/foo/).to_stderr_from_any_process + expect { logger.deprecate('#old', '#new', id: :bar) }.to output(/bar/).to_stderr_from_any_process + expect { logger.deprecate('#old', '#new', id: :foobar) }.not_to output.to_stderr_from_any_process end it 'logs only allowed ids from Array' do logger.allow(%i[foo bar]) - expect { logger.deprecate('#old', '#new', id: :foo) }.to output(/foo/).to_stdout_from_any_process - expect { logger.deprecate('#old', '#new', id: :bar) }.to output(/bar/).to_stdout_from_any_process - expect { logger.deprecate('#old', '#new', id: :foobar) }.not_to output.to_stdout_from_any_process + expect { logger.deprecate('#old', '#new', id: :foo) }.to output(/foo/).to_stderr_from_any_process + expect { logger.deprecate('#old', '#new', id: :bar) }.to output(/bar/).to_stderr_from_any_process + expect { logger.deprecate('#old', '#new', id: :foobar) }.not_to output.to_stderr_from_any_process end it 'prevents logging any deprecation when ignoring :deprecations' do logger.allow(:deprecations) - expect { logger.deprecate('#old', '#new') }.to output(/new/).to_stdout_from_any_process + expect { logger.deprecate('#old', '#new') }.to output(/new/).to_stderr_from_any_process end end end