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>
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 1d95f1f..3f94483 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 static void debug(Object arg0) {
MDC.put(classNameProp, "");
- debugLogger.debug("" + arg0);
+ debugLogger.debug("{}", arg0);
}
/**
@@ -765,7 +765,7 @@
MDC.put(STATUS_CODE, COMPLETE_STATUS);
MDC.put(RESPONSE_CODE, "0");
MDC.put(classNameProp, "");
- auditLogger.info("" + arg0);
+ auditLogger.info("{}", arg0);
}
/**
@@ -783,7 +783,7 @@
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 static void trace(Object arg0) {
MDC.put(classNameProp, "");
- debugLogger.trace("" + arg0);
+ debugLogger.trace("{}", arg0);
}
/**
@@ -879,13 +879,13 @@
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 @@
if (eventTracker != null && eventTracker.getEventDataByRequestId(eventId) != null) {
eventTracker.remove(eventId);
- debugLogger.info("eventTracker.remove(" + eventId + ")");
+ debugLogger.info("eventTracker.remove({})", eventId);
}
}
@@ -1249,9 +1249,9 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 8688ea3..1c412dd 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 @@
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 @@
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 @@
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 @@
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 1245e16..8085aa3 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 @@
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 @@
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