Skip to content

Commit 12bc023

Browse files
committed
[grid] use a message template when the log message is most likely dropped
1 parent f0da49b commit 12bc023

8 files changed

Lines changed: 26 additions & 28 deletions

File tree

java/src/org/openqa/selenium/bidi/Connection.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public <X> CompletableFuture<X> send(Command<X> command) {
142142
try (JsonOutput out = JSON.newOutput(json).writeClassName(false)) {
143143
out.write(serialized.build());
144144
}
145-
LOG.log(getDebugLogLevel(), () -> String.format("-> %s", json));
145+
LOG.log(getDebugLogLevel(), "-> {0}", json);
146146
socket.sendText(json);
147147

148148
if (!command.getSendsResponse()) {
@@ -245,7 +245,7 @@ private void handle(CharSequence data) {
245245
// TODO: decode once, and once only
246246

247247
String asString = String.valueOf(data);
248-
LOG.log(getDebugLogLevel(), () -> String.format("<- %s", asString));
248+
LOG.log(getDebugLogLevel(), "<- {0}", asString);
249249

250250
Map<String, Object> raw = JSON.toType(asString, MAP_TYPE);
251251
if (raw.get("id") instanceof Number
@@ -304,8 +304,8 @@ private void handleEventResponse(Map<String, Object> rawDataMap) {
304304
event -> {
305305
LOG.log(
306306
getDebugLogLevel(),
307-
String.format(
308-
"Matching %s with %s", rawDataMap.get("method"), event.getMethod()));
307+
"Matching {0} with {1}",
308+
new Object[] { rawDataMap.get("method"), event.getMethod() });
309309
return rawDataMap.get("method").equals(event.getMethod());
310310
})
311311
.forEach(
@@ -326,9 +326,8 @@ private void handleEventResponse(Map<String, Object> rawDataMap) {
326326
Consumer<Object> obj = (Consumer<Object>) action;
327327
LOG.log(
328328
getDebugLogLevel(),
329-
String.format(
330-
"Calling callback for %s using %s being passed %s",
331-
event, obj, finalValue));
329+
"Calling callback for {0} using {1} being passed {2}",
330+
new Object[] { event, obj, finalValue });
332331
obj.accept(finalValue);
333332
}
334333
});

java/src/org/openqa/selenium/devtools/Connection.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ public <X> CompletableFuture<X> send(SessionID sessionId, Command<X> command) {
156156
try (JsonOutput out = JSON.newOutput(json).writeClassName(false)) {
157157
out.write(serialized.build());
158158
}
159-
LOG.log(getDebugLogLevel(), () -> String.format("-> %s", json));
159+
LOG.log(getDebugLogLevel(), "-> {0}", json);
160160
socket.sendText(json);
161161

162162
if (!command.getSendsResponse()) {
@@ -236,7 +236,7 @@ private void handle(CharSequence data) {
236236
// TODO: decode once, and once only
237237

238238
String asString = String.valueOf(data);
239-
LOG.log(getDebugLogLevel(), () -> String.format("<- %s", asString));
239+
LOG.log(getDebugLogLevel(), "<- {0}", asString);
240240

241241
Map<String, Object> raw = JSON.toType(asString, MAP_TYPE);
242242
if (raw.get("id") instanceof Number
@@ -270,9 +270,8 @@ private void handle(CharSequence data) {
270270
} else if (raw.get("method") instanceof String && raw.get("params") instanceof Map) {
271271
LOG.log(
272272
getDebugLogLevel(),
273-
String.format(
274-
"Method %s called with %d callbacks available",
275-
raw.get("method"), eventCallbacks.keySet().size()));
273+
"Method {0} called with {1} callbacks available",
274+
new Object[] { raw.get("method"), eventCallbacks.keySet().size() });
276275
Lock lock = callbacksLock.readLock();
277276
lock.lock();
278277
try {
@@ -282,7 +281,8 @@ private void handle(CharSequence data) {
282281
event ->
283282
LOG.log(
284283
getDebugLogLevel(),
285-
String.format("Matching %s with %s", raw.get("method"), event.getMethod())))
284+
"Matching {0} with {1}",
285+
new Object[]{ raw.get("method"), event.getMethod()}))
286286
.filter(event -> raw.get("method").equals(event.getMethod()))
287287
.forEach(
288288
event -> {
@@ -316,9 +316,8 @@ private void handle(CharSequence data) {
316316
Consumer<Object> obj = (Consumer<Object>) action;
317317
LOG.log(
318318
getDebugLogLevel(),
319-
String.format(
320-
"Calling callback for %s using %s being passed %s",
321-
event, obj, finalValue));
319+
"Calling callback for {0} using {1} being passed {2}",
320+
new Object[] { event, obj, finalValue });
322321
obj.accept(finalValue);
323322
}
324323
}

java/src/org/openqa/selenium/grid/distributor/GridModel.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public void add(NodeStatus node) {
9797
&& next.getExternalUri().equals(node.getExternalUri())) {
9898
iterator.remove();
9999

100-
LOG.log(Debug.getDebugLogLevel(), "Refreshing node with id %s", node.getNodeId());
100+
LOG.log(Debug.getDebugLogLevel(), "Refreshing node with id {0}", node.getNodeId());
101101
NodeStatus refreshed = rewrite(node, next.getAvailability());
102102
nodes.add(refreshed);
103103
nodePurgeTimes.put(refreshed.getNodeId(), Instant.now());
@@ -135,8 +135,8 @@ public void add(NodeStatus node) {
135135
// Nodes are initially added in the "down" state until something changes their availability
136136
LOG.log(
137137
Debug.getDebugLogLevel(),
138-
String.format(
139-
"Adding node with id %s and URI %s", node.getNodeId(), node.getExternalUri()));
138+
"Adding node with id {0} and URI {1}",
139+
new Object[]{ node.getNodeId(), node.getExternalUri()});
140140
NodeStatus refreshed = rewrite(node, DOWN);
141141
nodes.add(refreshed);
142142
nodePurgeTimes.put(refreshed.getNodeId(), Instant.now());

java/src/org/openqa/selenium/grid/distributor/local/LocalDistributor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,7 @@ private void handleNewSessionRequest(SessionRequest sessionRequest) {
830830
try (Span childSpan = span.createSpan("distributor.retry")) {
831831
LOG.log(
832832
Debug.getDebugLogLevel(),
833-
String.format("Retrying %s", sessionRequest.getDesiredCapabilities()));
833+
"Retrying {0}", sessionRequest.getDesiredCapabilities());
834834
boolean retried = sessionQueue.retryAddToQueue(sessionRequest);
835835

836836
attributeMap.put("request.retry_add", EventAttribute.setValue(retried));

java/src/org/openqa/selenium/grid/node/local/LocalNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ private void checkSessionCount() {
902902
int remainingSessions = this.sessionCount.decrementAndGet();
903903
LOG.log(
904904
Debug.getDebugLogLevel(),
905-
String.format("%s remaining sessions before draining Node", remainingSessions));
905+
"{0} remaining sessions before draining Node", remainingSessions);
906906
if (remainingSessions <= 0) {
907907
LOG.info(
908908
String.format(

java/src/org/openqa/selenium/grid/node/relay/RelaySessionFactory.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ public boolean isServiceUp() {
220220
HttpClient client = clientFactory.createClient(serviceStatusUrl);
221221
HttpResponse response =
222222
client.execute(new HttpRequest(HttpMethod.GET, serviceStatusUrl.toString()));
223-
LOG.log(Debug.getDebugLogLevel(), Contents.string(response));
223+
LOG.log(Debug.getDebugLogLevel(), () -> Contents.string(response));
224224
return response.getStatus() == 200;
225225
} catch (Exception e) {
226226
LOG.log(

java/src/org/openqa/selenium/netty/server/RequestConverter.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,10 @@ class RequestConverter extends SimpleChannelInboundHandler<HttpObject> {
5959

6060
@Override
6161
protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception {
62-
LOG.log(Debug.getDebugLogLevel(), "Incoming message: " + msg);
62+
LOG.log(Debug.getDebugLogLevel(), "Incoming message: {0}", msg);
6363

6464
if (msg instanceof io.netty.handler.codec.http.HttpRequest) {
65-
LOG.log(Debug.getDebugLogLevel(), "Start of http request: " + msg);
65+
LOG.log(Debug.getDebugLogLevel(), "Start of http request: {0}", msg);
6666

6767
io.netty.handler.codec.http.HttpRequest nettyRequest =
6868
(io.netty.handler.codec.http.HttpRequest) msg;
@@ -110,7 +110,7 @@ protected void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Ex
110110
}
111111

112112
if (msg instanceof LastHttpContent) {
113-
LOG.log(Debug.getDebugLogLevel(), "End of http request: " + msg);
113+
LOG.log(Debug.getDebugLogLevel(), "End of http request: {0}", msg);
114114

115115
if (buffer != null) {
116116
ByteSource source = buffer.asByteSource();

java/src/org/openqa/selenium/remote/RemoteWebDriver.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -636,13 +636,13 @@ protected void log(SessionId sessionId, String commandName, Object toLog, When w
636636
}
637637
switch (when) {
638638
case BEFORE:
639-
LOG.log(level, "Executing: " + commandName + " " + text);
639+
LOG.log(level, "Executing: {0} {1}", new Object[] {commandName, text});
640640
break;
641641
case AFTER:
642-
LOG.log(level, "Executed: " + commandName + " " + text);
642+
LOG.log(level, "Executed: {0} {1}", new Object[] {commandName, text});
643643
break;
644644
case EXCEPTION:
645-
LOG.log(level, "Exception: " + commandName + " " + text);
645+
LOG.log(level, "Exception: {0} {1}", new Object[] {commandName, text});
646646
break;
647647
default:
648648
LOG.log(level, text);

0 commit comments

Comments
 (0)