Skip to content

Commit 4d84741

Browse files
committed
refactor(robot-extension): replace concatenation by parameterized message on logging
1 parent 4f51807 commit 4d84741

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

source/src/main/java/org/cerberus/core/service/robotextension/impl/SikuliService.java

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,14 @@ private JSONObject getContentBase64FromLocator(String locator) {
182182
try {
183183
xOffset = Integer.valueOf(xOffsetS);
184184
} catch (NumberFormatException e) {
185-
LOG.warn("Failed to convert xOffset : " + xOffsetS, e);
185+
LOG.warn("Failed to convert xOffset : {}", xOffsetS, e);
186186
}
187187
}
188188
if (!StringUtil.isEmptyOrNull(yOffsetS)) {
189189
try {
190190
yOffset = Integer.valueOf(yOffsetS);
191191
} catch (NumberFormatException e) {
192-
LOG.warn("Failed to convert xOffset : " + yOffsetS, e);
192+
LOG.warn("Failed to convert xOffset : {}", yOffsetS, e);
193193
}
194194
}
195195
}
@@ -250,17 +250,17 @@ public boolean isSikuliServerReachableOnRobot(Session session) {
250250
*/
251251
url = new URL(urlToConnect);
252252
connection = (HttpURLConnection) url.openConnection();
253-
LOG.debug("Trying to connect to: " + urlToConnect);
253+
LOG.debug("Trying to connect to: {}.", urlToConnect);
254254

255255
if (connection != null) {
256-
LOG.debug("Answer from Server: " + connection.getResponseCode());
256+
LOG.debug("Answer from Server: {}", connection.getResponseCode());
257257
}
258258

259259
if (connection == null || connection.getResponseCode() != 200) {
260260
return false;
261261
}
262262
} catch (ConnectException exception) { //Handle Sikuli not reachable with Selenium 4
263-
LOG.info("Robot extension not reachable.");
263+
LOG.info("Robot extension not reachable at '{}'.", urlToConnect);
264264
return false;
265265
} catch (IOException ex) {
266266
LOG.warn(ex);
@@ -293,21 +293,21 @@ public boolean isSikuliServerReachableOnNode(Session session) {
293293
connection = (HttpURLConnection) url.openConnection();
294294
connection.setConnectTimeout(5000);
295295
connection.setReadTimeout(5000);
296-
LOG.debug("Trying to connect to: " + urlToConnect);
296+
LOG.debug("Trying to connect to: {}", urlToConnect);
297297

298298
if (connection != null) {
299-
LOG.debug("Answer from Server: " + connection.getResponseCode());
299+
LOG.debug("Answer from Server: {}", connection.getResponseCode());
300300
}
301301

302302
if (connection == null || connection.getResponseCode() != 200) {
303-
LOG.warn("Response code different from 200 when calling '" + urlToConnect + "'");
303+
LOG.warn("Response code different from 200 when calling '{}'", urlToConnect);
304304
return false;
305305
}
306306
} catch (ConnectException exception) { //Handle Sikuli not reachable with Selenium 4
307-
LOG.info("Robot extension not reachable.");
307+
LOG.info("Robot extension not reachable at '{}'.", urlToConnect);
308308
return false;
309309
} catch (IOException ex) {
310-
LOG.warn("Exception catch when calling '" + urlToConnect + "' " + ex, ex);
310+
LOG.warn("Exception catch when calling '{}' {}", urlToConnect, ex, ex);
311311
return false;
312312
} finally {
313313
if (os != null) {
@@ -340,11 +340,11 @@ public AnswerItem<JSONObject> doSikuliAction(Session session, String action, Str
340340
if (session.getExecutorExtensionProxyPort() > 0) {
341341
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(session.getHost(), session.getExecutorExtensionProxyPort()));
342342

343-
LOG.info("Open Connection to Robot Node Sikuli (using proxy : " + session.getHost() + ":" + session.getExecutorExtensionProxyPort() + ") : " + urlToConnect);
343+
LOG.info("Open Connection to Robot Node Sikuli (using proxy : {}:{}) : {}", session.getHost(), session.getExecutorExtensionProxyPort(), urlToConnect);
344344
connection = (HttpURLConnection) url.openConnection(proxy);
345345

346346
} else {
347-
LOG.info("Open Connection to Robot Node Sikuli : " + urlToConnect);
347+
LOG.info("Open Connection to Robot Node Sikuli : {}", urlToConnect);
348348
connection = (HttpURLConnection) url.openConnection();
349349
}
350350
// We let Sikuli extension the sikuli timeout + 60 s to perform the action/control.
@@ -365,14 +365,14 @@ public AnswerItem<JSONObject> doSikuliAction(Session session, String action, Str
365365

366366
// Send post request
367367
os = new PrintStream(connection.getOutputStream());
368-
LOG.debug("Sending JSON : " + postParameters.toString());
368+
LOG.debug("Sending JSON : {}", postParameters.toString());
369369
os.println(postParameters.toString());
370370
// os.println("|ENDS|");
371371

372372
if (connection == null) {
373373
LOG.warn("No response from Robot Node Sikuli !!");
374374
} else {
375-
LOG.debug("Robot Node Sikuli http response status code : " + connection.getResponseCode());
375+
LOG.debug("Robot Node Sikuli http response status code : {}", connection.getResponseCode());
376376
}
377377

378378
if (connection == null || connection.getResponseCode() != 200) {
@@ -395,7 +395,7 @@ public AnswerItem<JSONObject> doSikuliAction(Session session, String action, Str
395395
}
396396
}
397397

398-
LOG.debug("Robot Node Sikuli Answer: " + response.toString());
398+
LOG.debug("Robot Node Sikuli Answer: {}", response.toString());
399399

400400
if (response.toString() != null && response.length() > 0) {
401401
/**
@@ -438,7 +438,7 @@ public AnswerItem<JSONObject> doSikuliAction(Session session, String action, Str
438438
msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_ROBOTEXTENSION_SERVER_BADURL);
439439
msg.resolveDescription("URL", urlToConnect);
440440
} catch (JSONException ex) {
441-
LOG.warn("Exception when converting response to JSON : " + response.toString(), ex);
441+
LOG.warn("Exception when converting response to JSON : {}", response.toString(), ex);
442442
msg = new MessageEvent(MessageEventEnum.ACTION_FAILED);
443443
} catch (MimeTypeException ex) {
444444
LOG.warn(ex, ex);
@@ -845,7 +845,7 @@ public File takeScreenShotFile(Session session) {
845845

846846
if (image != null) {
847847
//logs for debug purposes
848-
LOG.info("Screenshot taken with succes: " + image.getName() + " (size : " + image.length() + " b)");
848+
LOG.info("Screenshot taken with success: {} (size : {} b)", image.getName(), image.length());
849849
} else {
850850
LOG.warn("Screenshot returned null: ");
851851
}

0 commit comments

Comments
 (0)