Skip to content

Commit 7ef0fe2

Browse files
committed
[java] allow changing chromium driver log timestamp formatting
1 parent 18beade commit 7ef0fe2

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

java/src/org/openqa/selenium/chrome/ChromeDriverService.java

+21
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public class ChromeDriverService extends DriverService {
4646
*/
4747
public static final String CHROME_DRIVER_EXE_PROPERTY = "webdriver.chrome.driver";
4848

49+
/**
50+
* System property that toggles the formatting of the timestamps of the logs
51+
*/
52+
public static final String CHROME_DRIVER_READABLE_TIMESTAMP = "webdriver.chrome.readableTimestamp";
53+
4954
/**
5055
* System property that defines the default location where ChromeDriver output is logged.
5156
*/
@@ -155,6 +160,7 @@ public static class Builder extends DriverService.Builder<
155160
ChromeDriverService, ChromeDriverService.Builder> {
156161

157162
private boolean disableBuildCheck = Boolean.getBoolean(CHROME_DRIVER_DISABLE_BUILD_CHECK);
163+
private boolean readableTimestamp = Boolean.getBoolean(CHROME_DRIVER_READABLE_TIMESTAMP);
158164
private boolean appendLog = Boolean.getBoolean(CHROME_DRIVER_APPEND_LOG_PROPERTY);
159165
private boolean verbose = Boolean.getBoolean(CHROME_DRIVER_VERBOSE_LOG_PROPERTY);
160166
private boolean silent = Boolean.getBoolean(CHROME_DRIVER_SILENT_OUTPUT_PROPERTY);
@@ -252,6 +258,17 @@ public Builder withWhitelistedIps(String whitelistedIps) {
252258
return this;
253259
}
254260

261+
/**
262+
* Configures the format of the logging for the driver server.
263+
*
264+
* @param readableTimestamp Whether the timestamp of the log is readable.
265+
* @return A self reference.
266+
*/
267+
public Builder withReadableTimestamp(Boolean readableTimestamp) {
268+
this.readableTimestamp = readableTimestamp;
269+
return this;
270+
}
271+
255272
@Override
256273
protected File findDefaultExecutable() {
257274
return findExecutable(
@@ -282,6 +299,10 @@ protected List<String> createArgs() {
282299
args.add(String.format("--port=%d", getPort()));
283300
if (getLogFile() != null) {
284301
args.add(String.format("--log-path=%s", getLogFile().getAbsolutePath()));
302+
// This flag only works when logged to file
303+
if (readableTimestamp) {
304+
args.add("--readable-timestamp");
305+
}
285306
}
286307
if (appendLog) {
287308
args.add("--append-log");

java/src/org/openqa/selenium/edge/EdgeDriverService.java

+21
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ public class EdgeDriverService extends DriverService {
4646
*/
4747
public static final String EDGE_DRIVER_EXE_PROPERTY = "webdriver.edge.driver";
4848

49+
/**
50+
* System property that toggles the formatting of the timestamps of the logs
51+
*/
52+
public static final String EDGE_DRIVER_READABLE_TIMESTAMP = "webdriver.edge.readableTimestamp";
53+
4954
/**
5055
* System property that defines the default location where MSEdgeDriver output is logged.
5156
*/
@@ -124,6 +129,7 @@ public static class Builder extends DriverService.Builder<
124129
EdgeDriverService, Builder> {
125130

126131
private boolean disableBuildCheck = Boolean.getBoolean(EDGE_DRIVER_DISABLE_BUILD_CHECK);
132+
private boolean readableTimestamp = Boolean.getBoolean(EDGE_DRIVER_READABLE_TIMESTAMP);
127133
private boolean appendLog = Boolean.getBoolean(EDGE_DRIVER_APPEND_LOG_PROPERTY);
128134
private boolean verbose = Boolean.getBoolean(EDGE_DRIVER_VERBOSE_LOG_PROPERTY);
129135
private String logLevel = System.getProperty(EDGE_DRIVER_LOG_LEVEL_PROPERTY);
@@ -222,6 +228,17 @@ public Builder withAllowedListIps(String allowedListIps) {
222228
return this;
223229
}
224230

231+
/**
232+
* Configures the format of the logging for the driver server.
233+
*
234+
* @param readableTimestamp Whether the timestamp of the log is readable.
235+
* @return A self reference.
236+
*/
237+
public Builder withReadableTimestamp(Boolean readableTimestamp) {
238+
this.readableTimestamp = readableTimestamp;
239+
return this;
240+
}
241+
225242
@Override
226243
protected File findDefaultExecutable() {
227244
return findExecutable(
@@ -252,6 +269,10 @@ protected List<String> createArgs() {
252269
args.add(String.format("--port=%d", getPort()));
253270
if (getLogFile() != null) {
254271
args.add(String.format("--log-path=%s", getLogFile().getAbsolutePath()));
272+
// This flag only works when logged to file
273+
if (readableTimestamp) {
274+
args.add("--readable-timestamp");
275+
}
255276
}
256277
if (appendLog) {
257278
args.add("--append-log");

0 commit comments

Comments
 (0)