Skip to content

Commit 80d35e0

Browse files
committed
Implementing ability to configure firefox log target using driver service builder or a system property. Sending logs to null output stream by default. Fixes #4136
1 parent 33bd44b commit 80d35e0

File tree

2 files changed

+35
-19
lines changed

2 files changed

+35
-19
lines changed

java/client/src/org/openqa/selenium/firefox/GeckoDriverService.java

+17-15
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,24 @@ protected GeckoDriverService createDriverService(File exe, int port,
134134
ImmutableMap<String, String> environment) {
135135
try {
136136
GeckoDriverService service = new GeckoDriverService(exe, port, args, environment);
137-
if (getLogFile() != null) {
138-
// TODO: This stream is leaked.
139-
service.sendOutputTo(new FileOutputStream(getLogFile()));
137+
String firefoxLogFile = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE);
138+
if (firefoxLogFile != null) { // System property has higher precedence
139+
if ("/dev/stdout".equals(firefoxLogFile)) {
140+
service.sendOutputTo(System.out);
141+
} else if ("/dev/stderr".equals(firefoxLogFile)) {
142+
service.sendOutputTo(System.err);
143+
} else if ("/dev/null".equals(firefoxLogFile)) {
144+
service.sendOutputTo(ByteStreams.nullOutputStream());
145+
} else {
146+
// TODO: The stream is leaked.
147+
service.sendOutputTo(new FileOutputStream(firefoxLogFile));
148+
}
140149
} else {
141-
String firefoxLogFile = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE);
142-
if (firefoxLogFile != null) {
143-
if ("/dev/stdout".equals(firefoxLogFile)) {
144-
service.sendOutputTo(System.out);
145-
} else if ("/dev/stderr".equals(firefoxLogFile)) {
146-
service.sendOutputTo(System.err);
147-
} else if ("/dev/null".equals(firefoxLogFile)) {
148-
service.sendOutputTo(ByteStreams.nullOutputStream());
149-
} else {
150-
// TODO: The stream is leaked.
151-
service.sendOutputTo(new FileOutputStream(firefoxLogFile));
152-
}
150+
if (getLogFile() != null) {
151+
// TODO: This stream is leaked.
152+
service.sendOutputTo(new FileOutputStream(getLogFile()));
153+
} else {
154+
service.sendOutputTo(ByteStreams.nullOutputStream());
153155
}
154156
}
155157
return service;

java/client/src/org/openqa/selenium/firefox/XpiDriverService.java

+18-4
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import com.google.common.base.Preconditions;
2525
import com.google.common.collect.ImmutableList;
2626
import com.google.common.collect.ImmutableMap;
27+
import com.google.common.io.ByteStreams;
2728

2829
import org.openqa.selenium.WebDriverException;
2930
import org.openqa.selenium.firefox.internal.ClasspathExtension;
@@ -56,7 +57,8 @@ private XpiDriverService(
5657
ImmutableList<String> args,
5758
ImmutableMap<String, String> environment,
5859
FirefoxBinary binary,
59-
FirefoxProfile profile)
60+
FirefoxProfile profile,
61+
File logFile)
6062
throws IOException {
6163
super(executable, port, args, environment);
6264

@@ -67,13 +69,24 @@ private XpiDriverService(
6769
this.profile = profile;
6870

6971
String firefoxLogFile = System.getProperty(FirefoxDriver.SystemProperty.BROWSER_LOGFILE);
70-
71-
if (firefoxLogFile != null) {
72+
if (firefoxLogFile != null) { // System property has higher precedence
7273
if ("/dev/stdout".equals(firefoxLogFile)) {
7374
sendOutputTo(System.out);
75+
} else if ("/dev/stderr".equals(firefoxLogFile)) {
76+
sendOutputTo(System.err);
77+
} else if ("/dev/null".equals(firefoxLogFile)) {
78+
sendOutputTo(ByteStreams.nullOutputStream());
7479
} else {
80+
// TODO: This stream is leaked.
7581
sendOutputTo(new FileOutputStream(firefoxLogFile));
7682
}
83+
} else {
84+
if (logFile != null) {
85+
// TODO: This stream is leaked.
86+
sendOutputTo(new FileOutputStream(logFile));
87+
} else {
88+
sendOutputTo(ByteStreams.nullOutputStream());
89+
}
7790
}
7891
}
7992

@@ -211,7 +224,8 @@ protected XpiDriverService createDriverService(
211224
args,
212225
environment,
213226
binary == null ? new FirefoxBinary() : binary,
214-
profile == null ? new FirefoxProfile() : profile);
227+
profile == null ? new FirefoxProfile() : profile,
228+
getLogFile());
215229
} catch (IOException e) {
216230
throw new WebDriverException(e);
217231
}

0 commit comments

Comments
 (0)