24
24
import com .google .common .base .Preconditions ;
25
25
import com .google .common .collect .ImmutableList ;
26
26
import com .google .common .collect .ImmutableMap ;
27
+ import com .google .common .io .ByteStreams ;
27
28
28
29
import org .openqa .selenium .WebDriverException ;
29
30
import org .openqa .selenium .firefox .internal .ClasspathExtension ;
@@ -56,7 +57,8 @@ private XpiDriverService(
56
57
ImmutableList <String > args ,
57
58
ImmutableMap <String , String > environment ,
58
59
FirefoxBinary binary ,
59
- FirefoxProfile profile )
60
+ FirefoxProfile profile ,
61
+ File logFile )
60
62
throws IOException {
61
63
super (executable , port , args , environment );
62
64
@@ -67,13 +69,24 @@ private XpiDriverService(
67
69
this .profile = profile ;
68
70
69
71
String firefoxLogFile = System .getProperty (FirefoxDriver .SystemProperty .BROWSER_LOGFILE );
70
-
71
- if (firefoxLogFile != null ) {
72
+ if (firefoxLogFile != null ) { // System property has higher precedence
72
73
if ("/dev/stdout" .equals (firefoxLogFile )) {
73
74
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 ());
74
79
} else {
80
+ // TODO: This stream is leaked.
75
81
sendOutputTo (new FileOutputStream (firefoxLogFile ));
76
82
}
83
+ } else {
84
+ if (logFile != null ) {
85
+ // TODO: This stream is leaked.
86
+ sendOutputTo (new FileOutputStream (logFile ));
87
+ } else {
88
+ sendOutputTo (ByteStreams .nullOutputStream ());
89
+ }
77
90
}
78
91
}
79
92
@@ -211,7 +224,8 @@ protected XpiDriverService createDriverService(
211
224
args ,
212
225
environment ,
213
226
binary == null ? new FirefoxBinary () : binary ,
214
- profile == null ? new FirefoxProfile () : profile );
227
+ profile == null ? new FirefoxProfile () : profile ,
228
+ getLogFile ());
215
229
} catch (IOException e ) {
216
230
throw new WebDriverException (e );
217
231
}
0 commit comments