Skip to content

Commit 6f37dba

Browse files
committed
[rb] logger defaults output to stderr instead of stdout
1 parent 7cbfdbd commit 6f37dba

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

rb/lib/selenium/webdriver/common/logger.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def deprecate(old, new = nil, id: [], reference: '', &block)
181181
private
182182

183183
def create_logger(name, level:)
184-
logger = ::Logger.new($stdout)
184+
logger = ::Logger.new($stderr)
185185
logger.progname = name
186186
logger.level = level
187187
logger.formatter = proc do |severity, time, progname, msg|

rb/spec/rspec_matchers.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
LEVELS.each do |level|
2323
RSpec::Matchers.define "have_#{level}" do |entry|
2424
match do |actual|
25-
# Suppresses logging output to stdout while ensuring that it is still happening
25+
# Suppresses logging output to stderr while ensuring that it is still happening
2626
default_output = Selenium::WebDriver.logger.io
2727
io = StringIO.new
2828
Selenium::WebDriver.logger.output = io

rb/spec/unit/selenium/devtools_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ module Selenium
3838
it 'can fall back to an older devtools if necessary' do
3939
msg1 = /Could not load selenium-devtools v#{version}. Trying older versions/
4040
msg2 = /Using selenium-devtools version v#{current_version}, some features may not work as expected/
41-
expect { described_class.load_version }.to output(match(msg1).and(match(msg2))).to_stdout_from_any_process
41+
expect { described_class.load_version }.to output(match(msg1).and(match(msg2))).to_stderr_from_any_process
4242
end
4343
end
4444
end

rb/spec/unit/selenium/webdriver/common/logger_spec.rb

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ module WebDriver
3535
it 'allows creating a logger with a different progname' do
3636
other_logger = described_class.new('NotSelenium')
3737
msg = /WARN NotSelenium message/
38-
expect { other_logger.warn('message') }.to output(msg).to_stdout_from_any_process
38+
expect { other_logger.warn('message') }.to output(msg).to_stderr_from_any_process
3939
end
4040

4141
it 'does not log info from constructor' do
@@ -72,8 +72,8 @@ module WebDriver
7272
end
7373

7474
describe '#output' do
75-
it 'outputs to stdout by default' do
76-
expect { logger.warn('message') }.to output(/WARN Selenium message/).to_stdout_from_any_process
75+
it 'outputs to stderr by default' do
76+
expect { logger.warn('message') }.to output(/WARN Selenium message/).to_stderr_from_any_process
7777
end
7878

7979
it 'allows output to file' do
@@ -90,17 +90,17 @@ module WebDriver
9090
before { logger.level = :debug }
9191

9292
it 'logs message' do
93-
expect { logger.debug 'String Value' }.to output(/DEBUG Selenium String Value/).to_stdout_from_any_process
93+
expect { logger.debug 'String Value' }.to output(/DEBUG Selenium String Value/).to_stderr_from_any_process
9494
end
9595

9696
it 'logs single id when set' do
9797
msg = /DEBUG Selenium \[:foo\] debug message/
98-
expect { logger.debug('debug message', id: :foo) }.to output(msg).to_stdout_from_any_process
98+
expect { logger.debug('debug message', id: :foo) }.to output(msg).to_stderr_from_any_process
9999
end
100100

101101
it 'logs multiple ids when set' do
102102
msg = /DEBUG Selenium \[:foo, :bar\] debug message/
103-
expect { logger.debug('debug message', id: %i[foo bar]) }.to output(msg).to_stdout_from_any_process
103+
expect { logger.debug('debug message', id: %i[foo bar]) }.to output(msg).to_stderr_from_any_process
104104
end
105105
end
106106

@@ -109,118 +109,118 @@ module WebDriver
109109
logger = described_class.new('Selenium', default_level: :info)
110110

111111
logger.debug('first')
112-
expect { logger.info('first') }.to output(/:logger_info/).to_stdout_from_any_process
113-
expect { logger.info('second') }.not_to output(/:logger_info/).to_stdout_from_any_process
112+
expect { logger.info('first') }.to output(/:logger_info/).to_stderr_from_any_process
113+
expect { logger.info('second') }.not_to output(/:logger_info/).to_stderr_from_any_process
114114
end
115115

116116
it 'logs message' do
117-
expect { logger.info 'String Value' }.to output(/INFO Selenium String Value/).to_stdout_from_any_process
117+
expect { logger.info 'String Value' }.to output(/INFO Selenium String Value/).to_stderr_from_any_process
118118
end
119119

120120
it 'logs single id when set' do
121121
msg = /INFO Selenium \[:foo\] info message/
122-
expect { logger.info('info message', id: :foo) }.to output(msg).to_stdout_from_any_process
122+
expect { logger.info('info message', id: :foo) }.to output(msg).to_stderr_from_any_process
123123
end
124124

125125
it 'logs multiple ids when set' do
126126
msg = /INFO Selenium \[:foo, :bar\] info message/
127-
expect { logger.info('info message', id: %i[foo bar]) }.to output(msg).to_stdout_from_any_process
127+
expect { logger.info('info message', id: %i[foo bar]) }.to output(msg).to_stderr_from_any_process
128128
end
129129
end
130130

131131
describe '#warn' do
132132
it 'logs message' do
133-
expect { logger.warn 'String Value' }.to output(/WARN Selenium String Value/).to_stdout_from_any_process
133+
expect { logger.warn 'String Value' }.to output(/WARN Selenium String Value/).to_stderr_from_any_process
134134
end
135135

136136
it 'logs single id when set' do
137137
msg = /WARN Selenium \[:foo\] warning message/
138-
expect { logger.warn('warning message', id: :foo) }.to output(msg).to_stdout_from_any_process
138+
expect { logger.warn('warning message', id: :foo) }.to output(msg).to_stderr_from_any_process
139139
end
140140

141141
it 'logs multiple ids when set' do
142142
msg = /WARN Selenium \[:foo, :bar\] warning message/
143-
expect { logger.warn('warning message', id: %i[foo bar]) }.to output(msg).to_stdout_from_any_process
143+
expect { logger.warn('warning message', id: %i[foo bar]) }.to output(msg).to_stderr_from_any_process
144144
end
145145
end
146146

147147
describe '#deprecate' do
148148
it 'allows to deprecate functionality with replacement' do
149149
message = /WARN Selenium \[DEPRECATION\] #old is deprecated\. Use #new instead\./
150-
expect { logger.deprecate('#old', '#new') }.to output(message).to_stdout_from_any_process
150+
expect { logger.deprecate('#old', '#new') }.to output(message).to_stderr_from_any_process
151151
end
152152

153153
it 'allows to deprecate functionality without replacement' do
154154
message = /WARN Selenium \[DEPRECATION\] #old is deprecated and will be removed in a future release\./
155-
expect { logger.deprecate('#old') }.to output(message).to_stdout_from_any_process
155+
expect { logger.deprecate('#old') }.to output(message).to_stderr_from_any_process
156156
end
157157

158158
it 'allows to deprecate functionality with a reference message' do
159159
ref_url = 'https://selenium.dev'
160160
warn_msg = 'WARN Selenium \[DEPRECATION\] #old is deprecated\. Use #new instead\.'
161161
message = /#{warn_msg} See explanation for this deprecation: #{ref_url}/
162-
expect { logger.deprecate('#old', '#new', reference: ref_url) }.to output(message).to_stdout_from_any_process
162+
expect { logger.deprecate('#old', '#new', reference: ref_url) }.to output(message).to_stderr_from_any_process
163163
end
164164

165165
it 'appends deprecation message with provided block' do
166166
message = /WARN Selenium \[DEPRECATION\] #old is deprecated\. Use #new instead\. More Details\./
167-
expect { logger.deprecate('#old', '#new') { 'More Details.' } }.to output(message).to_stdout_from_any_process
167+
expect { logger.deprecate('#old', '#new') { 'More Details.' } }.to output(message).to_stderr_from_any_process
168168
end
169169

170170
it 'logs single id when set' do
171171
msg = /WARN Selenium \[:foo\] warning message/
172-
expect { logger.warn('warning message', id: :foo) }.to output(msg).to_stdout_from_any_process
172+
expect { logger.warn('warning message', id: :foo) }.to output(msg).to_stderr_from_any_process
173173
end
174174

175175
it 'logs multiple ids when set' do
176176
msg = /WARN Selenium \[:foo, :bar\] warning message/
177-
expect { logger.warn('warning message', id: %i[foo bar]) }.to output(msg).to_stdout_from_any_process
177+
expect { logger.warn('warning message', id: %i[foo bar]) }.to output(msg).to_stderr_from_any_process
178178
end
179179
end
180180

181181
describe '#ignore' do
182182
it 'prevents logging when id' do
183183
logger.ignore(:foo)
184-
expect { logger.deprecate('#old', '#new', id: :foo) }.not_to output.to_stdout_from_any_process
184+
expect { logger.deprecate('#old', '#new', id: :foo) }.not_to output.to_stderr_from_any_process
185185
end
186186

187187
it 'prevents logging when ignoring multiple ids' do
188188
logger.ignore(:foo)
189189
logger.ignore(:bar)
190-
expect { logger.deprecate('#old', '#new', id: :foo) }.not_to output.to_stdout_from_any_process
191-
expect { logger.deprecate('#old', '#new', id: :bar) }.not_to output.to_stdout_from_any_process
190+
expect { logger.deprecate('#old', '#new', id: :foo) }.not_to output.to_stderr_from_any_process
191+
expect { logger.deprecate('#old', '#new', id: :bar) }.not_to output.to_stderr_from_any_process
192192
end
193193

194194
it 'prevents logging when ignoring Array of ids' do
195195
logger.ignore(%i[foo bar])
196-
expect { logger.deprecate('#old', '#new', id: %i[foo foobar]) }.not_to output.to_stdout_from_any_process
196+
expect { logger.deprecate('#old', '#new', id: %i[foo foobar]) }.not_to output.to_stderr_from_any_process
197197
end
198198

199199
it 'prevents logging any deprecation when ignoring :deprecations' do
200200
logger.ignore(:deprecations)
201-
expect { logger.deprecate('#old', '#new') }.not_to output.to_stdout_from_any_process
201+
expect { logger.deprecate('#old', '#new') }.not_to output.to_stderr_from_any_process
202202
end
203203
end
204204

205205
describe '#allow' do
206206
it 'logs only allowed ids from method' do
207207
logger.allow(:foo)
208208
logger.allow(:bar)
209-
expect { logger.deprecate('#old', '#new', id: :foo) }.to output(/foo/).to_stdout_from_any_process
210-
expect { logger.deprecate('#old', '#new', id: :bar) }.to output(/bar/).to_stdout_from_any_process
211-
expect { logger.deprecate('#old', '#new', id: :foobar) }.not_to output.to_stdout_from_any_process
209+
expect { logger.deprecate('#old', '#new', id: :foo) }.to output(/foo/).to_stderr_from_any_process
210+
expect { logger.deprecate('#old', '#new', id: :bar) }.to output(/bar/).to_stderr_from_any_process
211+
expect { logger.deprecate('#old', '#new', id: :foobar) }.not_to output.to_stderr_from_any_process
212212
end
213213

214214
it 'logs only allowed ids from Array' do
215215
logger.allow(%i[foo bar])
216-
expect { logger.deprecate('#old', '#new', id: :foo) }.to output(/foo/).to_stdout_from_any_process
217-
expect { logger.deprecate('#old', '#new', id: :bar) }.to output(/bar/).to_stdout_from_any_process
218-
expect { logger.deprecate('#old', '#new', id: :foobar) }.not_to output.to_stdout_from_any_process
216+
expect { logger.deprecate('#old', '#new', id: :foo) }.to output(/foo/).to_stderr_from_any_process
217+
expect { logger.deprecate('#old', '#new', id: :bar) }.to output(/bar/).to_stderr_from_any_process
218+
expect { logger.deprecate('#old', '#new', id: :foobar) }.not_to output.to_stderr_from_any_process
219219
end
220220

221221
it 'prevents logging any deprecation when ignoring :deprecations' do
222222
logger.allow(:deprecations)
223-
expect { logger.deprecate('#old', '#new') }.to output(/new/).to_stdout_from_any_process
223+
expect { logger.deprecate('#old', '#new') }.to output(/new/).to_stderr_from_any_process
224224
end
225225
end
226226
end

0 commit comments

Comments
 (0)