Skip to content

Commit bbf838e

Browse files
committed
java: Direct messages to the logger, stop polluting the console
1 parent 3e3f9ec commit bbf838e

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

Diff for: java/client/src/org/openqa/selenium/os/ProcessUtils.java

+14-15
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.io.IOException;
2626
import java.lang.reflect.Field;
27+
import java.util.logging.Level;
2728
import java.util.logging.Logger;
2829

2930
import static org.openqa.selenium.Platform.WINDOWS;
@@ -34,7 +35,8 @@
3435
import com.sun.jna.platform.win32.WinNT;
3536

3637
public class ProcessUtils {
37-
static Logger log = Logger.getLogger(ProcessUtils.class.getName());
38+
39+
private static Logger LOG = Logger.getLogger(ProcessUtils.class.getName());
3840

3941
/**
4042
* Waits the specified timeout for the process to die
@@ -106,13 +108,12 @@ private static int killUnixProcess(Process process) {
106108
throw ex;
107109
}
108110
try {
109-
log.info("Process didn't die after 10 seconds");
111+
LOG.info("Process didn't die after 10 seconds");
110112
kill9(process);
111113
exitValue = waitForProcessDeath(process, 10000);
112114
closeAllStreamsAndDestroyProcess( process);
113115
} catch (Exception e) {
114-
log.warning("Process refused to die after 10 seconds, and couldn't kill9 it");
115-
e.printStackTrace();
116+
LOG.log(Level.WARNING, "Process refused to die after 10 seconds, and couldn't kill9 it", ex);
116117
throw new RuntimeException(
117118
"Process refused to die after 10 seconds, and couldn't kill9 it: " + e.getMessage(),
118119
ex);
@@ -136,9 +137,8 @@ private static int killWinProcess(Process process) {
136137

137138
killPID("" + pid);
138139
exitValue = waitForProcessDeath(process, 10000);
139-
} catch (Throwable ex) {
140-
log.warning("Process refused to die after 10 seconds, and couldn't taskkill it");
141-
ex.printStackTrace();
140+
} catch (Exception ex) {
141+
LOG.log(Level.WARNING, "Process refused to die after 10 seconds, and couldn't taskkill it", ex);
142142
throw new RuntimeException(
143143
"Process refused to die after 10 seconds, and couldn't taskkill it: " + ex.getMessage(),
144144
ex);
@@ -151,14 +151,14 @@ private static class ProcessWaiter implements Runnable {
151151
private volatile InterruptedException t;
152152
private final Process p;
153153

154-
public InterruptedException getException() {
155-
return t;
156-
}
157-
158154
public ProcessWaiter(Process p) {
159155
this.p = p;
160156
}
161157

158+
public InterruptedException getException() {
159+
return t;
160+
}
161+
162162
public void run() {
163163
try {
164164
p.waitFor();
@@ -191,22 +191,21 @@ static int getProcessId(Process p) {
191191
try {
192192
Field f = p.getClass().getDeclaredField("pid");
193193
f.setAccessible(true);
194-
Integer pid = (Integer) f.get(p);
195-
return pid;
194+
return (Integer) f.get(p);
196195
} catch (Exception e) {
197196
throw new RuntimeException("Couldn't detect pid", e);
198197
}
199198
}
200199

201200
/** runs "kill -9" on the specified pid */
202201
private static void kill9(Integer pid) {
203-
log.fine("kill -9 " + pid);
202+
LOG.fine("kill -9 " + pid);
204203

205204
CommandLine command = new CommandLine("kill", "-9", pid.toString());
206205
command.execute();
207206
String result = command.getStdOut();
208207
int output = command.getExitCode();
209-
log.fine(String.valueOf(output));
208+
LOG.fine(String.valueOf(output));
210209
if (!command.isSuccessful()) {
211210
throw new RuntimeException("exec return code " + result + ": " + output);
212211
}

0 commit comments

Comments
 (0)