diff options
author | Jim Hahn <jrh3@att.com> | 2020-06-29 14:55:27 -0400 |
---|---|---|
committer | Jim Hahn <jrh3@att.com> | 2020-06-29 15:01:42 -0400 |
commit | f71f3fcb8c1e3138f92a3c773f19bf3280572def (patch) | |
tree | 645ff74ec20cc07d09038139940205bdedeade9a | |
parent | 25d1b68c099cedf9ce0bae12cf2b518b8ec39f01 (diff) |
Fix new logger sonars in policy-common
Not sure if this was introduced with the new logger version, but
now seeing a number of new sonars about using "{}". Fixed those.
Issue-ID: POLICY-2650
Change-Id: If36b2e89aa9151700bb9cea2906b6afaad5c4c72
Signed-off-by: Jim Hahn <jrh3@att.com>
3 files changed, 24 insertions, 24 deletions
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java index 1d95f1fd..3f94483b 100644 --- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java +++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java @@ -699,7 +699,7 @@ public class PolicyLogger { public static void debug(Object arg0) { MDC.put(classNameProp, ""); - debugLogger.debug("" + arg0); + debugLogger.debug("{}", arg0); } /** @@ -765,7 +765,7 @@ public class PolicyLogger { MDC.put(STATUS_CODE, COMPLETE_STATUS); MDC.put(RESPONSE_CODE, "0"); MDC.put(classNameProp, ""); - auditLogger.info("" + arg0); + auditLogger.info("{}", arg0); } /** @@ -783,7 +783,7 @@ public class PolicyLogger { MDC.put(RESPONSE_CODE, "0"); if (arguments.length == 1 && !OnapLoggingUtils.isThrowable(arguments[0])) { MDC.put(classNameProp, message); - auditLogger.info(arguments[0] == null ? "" : arguments[0].toString()); + auditLogger.info("{}", arguments[0] == null ? "" : arguments[0].toString()); return; } @@ -858,7 +858,7 @@ public class PolicyLogger { public static void trace(Object arg0) { MDC.put(classNameProp, ""); - debugLogger.trace("" + arg0); + debugLogger.trace("{}", arg0); } /** @@ -879,13 +879,13 @@ public class PolicyLogger { event.setStartTime(Instant.now()); eventTracker.storeEventData(event); MDC.put(MDC_KEY_REQUEST_ID, eventId); - debugLogger.info("CONCURRENTHASHMAP_LIMIT : " + concurrentHashMapLimit); + debugLogger.info("CONCURRENTHASHMAP_LIMIT : {}", concurrentHashMapLimit); // --- Tracking the size of the concurrentHashMap, if it is above limit, keep EventTrack // Timer running int size = eventTracker.getEventInfo().size(); - debugLogger.info("EventInfo concurrentHashMap Size : " + size + " on " + new Date()); - debugLogger.info("isEventTrackerRunning : " + isEventTrackerRunning); + debugLogger.info("EventInfo concurrentHashMap Size : {} on {}", size, new Date()); + debugLogger.info("isEventTrackerRunning : {}", isEventTrackerRunning); if (size >= concurrentHashMapLimit) { @@ -1084,7 +1084,7 @@ public class PolicyLogger { if (eventTracker != null && eventTracker.getEventDataByRequestId(eventId) != null) { eventTracker.remove(eventId); - debugLogger.info("eventTracker.remove(" + eventId + ")"); + debugLogger.info("eventTracker.remove({})", eventId); } } @@ -1249,9 +1249,9 @@ public class PolicyLogger { EventTrackInfoHandler ttrcker = new EventTrackInfoHandler(); timer = new Timer(true); timer.scheduleAtFixedRate(ttrcker, timerDelayTime, checkInterval); - debugLogger.info("EventTrackInfoHandler begins! : " + new Date()); + debugLogger.info("EventTrackInfoHandler begins! : {}", new Date()); } else { - debugLogger.info("Timer is still running : " + new Date()); + debugLogger.info("Timer is still running : {}", new Date()); } } @@ -1265,9 +1265,9 @@ public class PolicyLogger { if (isEventTrackerRunning && timer != null) { timer.cancel(); timer.purge(); - debugLogger.info("Timer stopped: " + new Date()); + debugLogger.info("Timer stopped: {}", new Date()); } else { - debugLogger.info("Timer was already stopped : " + new Date()); + debugLogger.info("Timer was already stopped : {}", new Date()); } isEventTrackerRunning = false; @@ -1301,7 +1301,7 @@ public class PolicyLogger { stopCheckPoint = getIntProp(loggerProperties, "stop.check.point", stopCheckPoint); component = loggerProperties.getProperty("policy.component", "DROOLS"); - debugLogger.info("component: " + component); + debugLogger.info("component: {}", component); return detmLoggerType(loggerProperties); @@ -1323,7 +1323,7 @@ public class PolicyLogger { private static int getIntProp(Properties properties, String propName, int defaultValue) { final int propValue = Integer.parseInt(properties.getProperty(propName, String.valueOf(defaultValue))); - debugLogger.info(propName + " value: " + propValue); + debugLogger.info("{} value: {}", propName, propValue); if (propValue > 0) { return propValue; @@ -1336,7 +1336,7 @@ public class PolicyLogger { ErrorCodeMap.getErrorCodeInfo(MessageCodes.GENERAL_ERROR).getErrorDesc()); } - errorLogger.error("failed to get the " + propName + ", so use its default value: " + defaultValue); + errorLogger.error("failed to get the {}, so use its default value: {}", propName, defaultValue); return defaultValue; } } @@ -1356,7 +1356,7 @@ public class PolicyLogger { final String propValue = properties.getProperty(propName, defaultValue); if (!StringUtils.isBlank(propValue)) { - debugLogger.info(propName + " level: " + propValue); + debugLogger.info("{} level: {}", propName, propValue); } setter.accept(propValue); @@ -1366,7 +1366,7 @@ public class PolicyLogger { final String propValue = properties.getProperty(propName, "ON"); if (Level.OFF.toString().equalsIgnoreCase(propValue)) { - debugLogger.info(propName + " level: " + propValue); + debugLogger.info("{} level: {}", propName, propValue); } setter.accept(propValue); @@ -1382,7 +1382,7 @@ public class PolicyLogger { private static LoggerType detmLoggerType(Properties loggerProperties) { final String loggerTypeProp = loggerProperties.getProperty("logger.type", LoggerType.EELF.toString()); - debugLogger.info("loggerType value: " + loggerTypeProp); + debugLogger.info("loggerType value: {}", loggerTypeProp); switch (loggerTypeProp.toUpperCase()) { case "EELF": diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java index 8688ea3d..1c412ddc 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/eelf/PolicyLoggerTest.java @@ -383,7 +383,7 @@ public class PolicyLoggerTest { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.debug(1); - Mockito.verify(mockLogger).debug("1"); + Mockito.verify(mockLogger).debug("{}", 1); } @Test @@ -396,7 +396,7 @@ public class PolicyLoggerTest { PolicyLogger.audit("PolicyLoggerTest", 1); assertEquals("PolicyLoggerTest", MDC.get("ClassName")); assertEquals("COMPLETE", MDC.get("StatusCode")); - Mockito.verify(mockLogger).info("1"); + Mockito.verify(mockLogger).info("{}", "1"); } @Test @@ -406,7 +406,7 @@ public class PolicyLoggerTest { PolicyLogger.audit(1); assertEquals("", MDC.get("ClassName")); assertEquals("COMPLETE", MDC.get("StatusCode")); - Mockito.verify(mockLogger).info("1"); + Mockito.verify(mockLogger).info("{}", 1); } @Test @@ -495,7 +495,7 @@ public class PolicyLoggerTest { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger); PolicyLogger.trace(1); - Mockito.verify(mockLogger).trace("1"); + Mockito.verify(mockLogger).trace("{}", 1); } @Test diff --git a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java index 1245e164..8085aa3a 100644 --- a/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java +++ b/common-logging/src/test/java/org/onap/policy/common/logging/flexlogger/EelfLoggerTest.java @@ -252,7 +252,7 @@ public class EelfLoggerTest { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); Whitebox.setInternalState(PolicyLogger.class, "debugLogger", mockLogger); eelfLogger.trace("message", new NullPointerException()); - Mockito.verify(mockLogger).trace("message"); + Mockito.verify(mockLogger).trace("{}", "message"); } @Test @@ -260,7 +260,7 @@ public class EelfLoggerTest { EELFLogger mockLogger = Mockito.mock(EELFLogger.class); Whitebox.setInternalState(PolicyLogger.class, "auditLogger", mockLogger); eelfLogger.audit("message", new NullPointerException()); - Mockito.verify(mockLogger).info("message"); + Mockito.verify(mockLogger).info("{}", "message"); } @Test |