Skip to content

Commit 047fe88

Browse files
committed
[java] use message templates in logger calls
1 parent 9077fba commit 047fe88

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

java/src/org/openqa/selenium/remote/http/jdk/JdkHttpClient.java

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,10 @@ public CompletionStage<?> onText(
185185
builder.append(data);
186186

187187
if (last) {
188-
LOG.fine(
189-
"Final part of text message received. Calling listener with " + builder);
188+
LOG.log(
189+
Level.FINE,
190+
"Final part of text message received. Calling listener with {0}",
191+
builder);
190192
listener.onText(builder.toString());
191193
builder.setLength(0);
192194
}
@@ -208,10 +210,11 @@ public CompletionStage<?> onBinary(
208210
}
209211

210212
if (last) {
211-
LOG.fine(
212-
"Final part of binary data received. Calling listener with "
213-
+ buffer.size()
214-
+ " bytes of data");
213+
LOG.log(
214+
Level.FINE,
215+
"Final part of binary data received. Calling listener with {0} bytes of"
216+
+ " data",
217+
buffer.size());
215218
listener.onBinary(buffer.toByteArray());
216219
buffer.reset();
217220
}
@@ -229,8 +232,7 @@ public CompletionStage<?> onClose(
229232

230233
@Override
231234
public void onError(java.net.http.WebSocket webSocket, Throwable error) {
232-
LOG.log(
233-
Level.FINE, error, () -> "An error has occurred: " + error.getMessage());
235+
LOG.log(Level.FINE, "An error has occurred: " + error.getMessage(), error);
234236
listener.onError(error);
235237
}
236238
});
@@ -267,19 +269,18 @@ public WebSocket send(Message message) {
267269
() -> underlyingSocket.sendBinary(ByteBuffer.wrap(binaryMessage.data()), true);
268270
} else if (message instanceof TextMessage) {
269271
TextMessage textMessage = (TextMessage) message;
270-
LOG.fine("Sending text message: " + textMessage.text());
272+
LOG.log(Level.FINE, "Sending text message: {0}", textMessage.text());
271273
makeCall = () -> underlyingSocket.sendText(textMessage.text(), true);
272274
} else if (message instanceof CloseMessage) {
273275
CloseMessage closeMessage = (CloseMessage) message;
274276
if (!underlyingSocket.isOutputClosed()) {
275277
// Sometimes the statusCode is -1, which could mean the socket is already closed.
276278
// We send a normal closure code in that case, though
277279
int statusCode = closeMessage.code() == -1 ? 1000 : closeMessage.code();
278-
LOG.fine(
279-
() ->
280-
String.format(
281-
"Sending close message, statusCode %s, reason: %s",
282-
statusCode, closeMessage.reason()));
280+
LOG.log(
281+
Level.FINE,
282+
"Sending close message, statusCode {0}, reason: {1}",
283+
new Object[] {statusCode, closeMessage.reason()});
283284
makeCall = () -> underlyingSocket.sendClose(statusCode, closeMessage.reason());
284285
} else {
285286
LOG.fine("Output is closed, not sending close message");
@@ -308,10 +309,10 @@ public WebSocket send(Message message) {
308309
} catch (java.util.concurrent.TimeoutException e) {
309310
throw new TimeoutException(e);
310311
} finally {
311-
LOG.fine(
312-
String.format(
313-
"Websocket response to %s read in %sms",
314-
message, (System.currentTimeMillis() - start)));
312+
LOG.log(
313+
Level.FINE,
314+
"Websocket response to {0} read in {1}ms",
315+
new Object[] {message, (System.currentTimeMillis() - start)});
315316
}
316317
}
317318
return this;
@@ -361,7 +362,7 @@ public HttpResponse execute(HttpRequest req) throws UncheckedIOException {
361362
private HttpResponse execute0(HttpRequest req) throws UncheckedIOException {
362363
Objects.requireNonNull(req, "Request");
363364

364-
LOG.fine("Executing request: " + req);
365+
LOG.log(Level.FINE, "Executing request: {0}", req);
365366
long start = System.currentTimeMillis();
366367

367368
BodyHandler<byte[]> byteHandler = BodyHandlers.ofByteArray();
@@ -444,8 +445,10 @@ private HttpResponse execute0(HttpRequest req) throws UncheckedIOException {
444445
Thread.currentThread().interrupt();
445446
throw new RuntimeException(e);
446447
} finally {
447-
LOG.fine(
448-
String.format("Ending request %s in %sms", req, (System.currentTimeMillis() - start)));
448+
LOG.log(
449+
Level.FINE,
450+
"Ending request {0} in {1}ms",
451+
new Object[] {req, (System.currentTimeMillis() - start)});
449452
}
450453
}
451454

0 commit comments

Comments
 (0)