From 0765271100b20e3dcf3b88aec69c859f425e123d Mon Sep 17 00:00:00 2001 From: Software Magico Date: Fri, 13 Sep 2024 13:31:16 +0200 Subject: [PATCH] Fixing sonarcloud recommendations --- .../softwaremagico/kt/logger/BasicLogger.java | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/backend/kendo-tournament-logger/src/main/java/com/softwaremagico/kt/logger/BasicLogger.java b/backend/kendo-tournament-logger/src/main/java/com/softwaremagico/kt/logger/BasicLogger.java index 43a2aeb88..8f7a072a1 100644 --- a/backend/kendo-tournament-logger/src/main/java/com/softwaremagico/kt/logger/BasicLogger.java +++ b/backend/kendo-tournament-logger/src/main/java/com/softwaremagico/kt/logger/BasicLogger.java @@ -54,13 +54,15 @@ public static void warning(Logger logger, String messageTemplate, Object... argu * @param arguments parameters to fill up the template */ public static void warning(Logger logger, String className, String messageTemplate, Object... arguments) { - for (int i = 0; i < arguments.length; i++) { - if (arguments[i] != null) { - arguments[i] = arguments[i].toString().replaceAll("[\n\r\t]", "_"); + if (logger.isWarnEnabled()) { + for (int i = 0; i < arguments.length; i++) { + if (arguments[i] != null) { + arguments[i] = arguments[i].toString().replaceAll("[\n\r\t]", "_"); + } } + final String templateWithClass = className + ": " + messageTemplate; + logger.warn(templateWithClass.replaceAll("[\n\r]", "_"), arguments); } - final String templateWithClass = className + ": " + messageTemplate; - logger.warn(templateWithClass.replaceAll("[\n\r]", "_"), arguments); } /** @@ -71,12 +73,14 @@ public static void warning(Logger logger, String className, String messageTempla * @param arguments parameters to fill up the template */ public static void info(Logger logger, String messageTemplate, Object... arguments) { - for (int i = 0; i < arguments.length; i++) { - if (arguments[i] != null) { - arguments[i] = arguments[i].toString().replaceAll("[\n\r\t]", "_"); + if (logger.isInfoEnabled()) { + for (int i = 0; i < arguments.length; i++) { + if (arguments[i] != null) { + arguments[i] = arguments[i].toString().replaceAll("[\n\r\t]", "_"); + } } + logger.info(messageTemplate.replaceAll("[\n\r]", "_"), arguments); } - logger.info(messageTemplate, arguments); } /** @@ -135,12 +139,14 @@ public static void debug(Logger logger, String className, String messageTemplate * @param arguments parameters to fill up the template */ protected static void severe(Logger logger, String messageTemplate, Object... arguments) { - for (int i = 0; i < arguments.length; i++) { - if (arguments[i] != null) { - arguments[i] = arguments[i].toString().replaceAll("[\n\r\t]", "_"); + if (logger.isErrorEnabled()) { + for (int i = 0; i < arguments.length; i++) { + if (arguments[i] != null) { + arguments[i] = arguments[i].toString().replaceAll("[\n\r\t]", "_"); + } } + logger.error(messageTemplate.replaceAll("[\n\r]", "_"), arguments); } - logger.error(messageTemplate, arguments); } /**