From 4d84741d6315a8c9d690f497639935c8ce580eaf Mon Sep 17 00:00:00 2001 From: lucashimpens Date: Thu, 13 Feb 2025 15:41:44 +0100 Subject: [PATCH] refactor(robot-extension): replace concatenation by parameterized message on logging --- .../robotextension/impl/SikuliService.java | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/source/src/main/java/org/cerberus/core/service/robotextension/impl/SikuliService.java b/source/src/main/java/org/cerberus/core/service/robotextension/impl/SikuliService.java index 5b5b46026..c460c6175 100644 --- a/source/src/main/java/org/cerberus/core/service/robotextension/impl/SikuliService.java +++ b/source/src/main/java/org/cerberus/core/service/robotextension/impl/SikuliService.java @@ -182,14 +182,14 @@ private JSONObject getContentBase64FromLocator(String locator) { try { xOffset = Integer.valueOf(xOffsetS); } catch (NumberFormatException e) { - LOG.warn("Failed to convert xOffset : " + xOffsetS, e); + LOG.warn("Failed to convert xOffset : {}", xOffsetS, e); } } if (!StringUtil.isEmptyOrNull(yOffsetS)) { try { yOffset = Integer.valueOf(yOffsetS); } catch (NumberFormatException e) { - LOG.warn("Failed to convert xOffset : " + yOffsetS, e); + LOG.warn("Failed to convert xOffset : {}", yOffsetS, e); } } } @@ -250,17 +250,17 @@ public boolean isSikuliServerReachableOnRobot(Session session) { */ url = new URL(urlToConnect); connection = (HttpURLConnection) url.openConnection(); - LOG.debug("Trying to connect to: " + urlToConnect); + LOG.debug("Trying to connect to: {}.", urlToConnect); if (connection != null) { - LOG.debug("Answer from Server: " + connection.getResponseCode()); + LOG.debug("Answer from Server: {}", connection.getResponseCode()); } if (connection == null || connection.getResponseCode() != 200) { return false; } } catch (ConnectException exception) { //Handle Sikuli not reachable with Selenium 4 - LOG.info("Robot extension not reachable."); + LOG.info("Robot extension not reachable at '{}'.", urlToConnect); return false; } catch (IOException ex) { LOG.warn(ex); @@ -293,21 +293,21 @@ public boolean isSikuliServerReachableOnNode(Session session) { connection = (HttpURLConnection) url.openConnection(); connection.setConnectTimeout(5000); connection.setReadTimeout(5000); - LOG.debug("Trying to connect to: " + urlToConnect); + LOG.debug("Trying to connect to: {}", urlToConnect); if (connection != null) { - LOG.debug("Answer from Server: " + connection.getResponseCode()); + LOG.debug("Answer from Server: {}", connection.getResponseCode()); } if (connection == null || connection.getResponseCode() != 200) { - LOG.warn("Response code different from 200 when calling '" + urlToConnect + "'"); + LOG.warn("Response code different from 200 when calling '{}'", urlToConnect); return false; } } catch (ConnectException exception) { //Handle Sikuli not reachable with Selenium 4 - LOG.info("Robot extension not reachable."); + LOG.info("Robot extension not reachable at '{}'.", urlToConnect); return false; } catch (IOException ex) { - LOG.warn("Exception catch when calling '" + urlToConnect + "' " + ex, ex); + LOG.warn("Exception catch when calling '{}' {}", urlToConnect, ex, ex); return false; } finally { if (os != null) { @@ -340,11 +340,11 @@ public AnswerItem doSikuliAction(Session session, String action, Str if (session.getExecutorExtensionProxyPort() > 0) { Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(session.getHost(), session.getExecutorExtensionProxyPort())); - LOG.info("Open Connection to Robot Node Sikuli (using proxy : " + session.getHost() + ":" + session.getExecutorExtensionProxyPort() + ") : " + urlToConnect); + LOG.info("Open Connection to Robot Node Sikuli (using proxy : {}:{}) : {}", session.getHost(), session.getExecutorExtensionProxyPort(), urlToConnect); connection = (HttpURLConnection) url.openConnection(proxy); } else { - LOG.info("Open Connection to Robot Node Sikuli : " + urlToConnect); + LOG.info("Open Connection to Robot Node Sikuli : {}", urlToConnect); connection = (HttpURLConnection) url.openConnection(); } // We let Sikuli extension the sikuli timeout + 60 s to perform the action/control. @@ -365,14 +365,14 @@ public AnswerItem doSikuliAction(Session session, String action, Str // Send post request os = new PrintStream(connection.getOutputStream()); - LOG.debug("Sending JSON : " + postParameters.toString()); + LOG.debug("Sending JSON : {}", postParameters.toString()); os.println(postParameters.toString()); // os.println("|ENDS|"); if (connection == null) { LOG.warn("No response from Robot Node Sikuli !!"); } else { - LOG.debug("Robot Node Sikuli http response status code : " + connection.getResponseCode()); + LOG.debug("Robot Node Sikuli http response status code : {}", connection.getResponseCode()); } if (connection == null || connection.getResponseCode() != 200) { @@ -395,7 +395,7 @@ public AnswerItem doSikuliAction(Session session, String action, Str } } - LOG.debug("Robot Node Sikuli Answer: " + response.toString()); + LOG.debug("Robot Node Sikuli Answer: {}", response.toString()); if (response.toString() != null && response.length() > 0) { /** @@ -438,7 +438,7 @@ public AnswerItem doSikuliAction(Session session, String action, Str msg = new MessageEvent(MessageEventEnum.ACTION_FAILED_ROBOTEXTENSION_SERVER_BADURL); msg.resolveDescription("URL", urlToConnect); } catch (JSONException ex) { - LOG.warn("Exception when converting response to JSON : " + response.toString(), ex); + LOG.warn("Exception when converting response to JSON : {}", response.toString(), ex); msg = new MessageEvent(MessageEventEnum.ACTION_FAILED); } catch (MimeTypeException ex) { LOG.warn(ex, ex); @@ -845,7 +845,7 @@ public File takeScreenShotFile(Session session) { if (image != null) { //logs for debug purposes - LOG.info("Screenshot taken with succes: " + image.getName() + " (size : " + image.length() + " b)"); + LOG.info("Screenshot taken with success: {} (size : {} b)", image.getName(), image.length()); } else { LOG.warn("Screenshot returned null: "); }