aboutsummaryrefslogtreecommitdiffstats
path: root/common-logging
diff options
context:
space:
mode:
authorMagnusen, Drew (dm741q) <dm741q@att.com>2017-08-02 13:00:23 -0500
committerMagnusen, Drew (dm741q) <dm741q@att.com>2017-08-04 08:02:00 -0500
commit09ca5f00b5fb88d35987e1922c34cae8469ed79d (patch)
tree4a91d76e1d51257bf2279e06cf96cbd760ae8e6e /common-logging
parenta7ab43dbd252c5bc70e490f4db94940e6985f25a (diff)
[POLICY-98] Code cleanup for sonar issues.
Modified code in ECOMP-Logging to resolve critical/major sonar issues. Not all issues were resolved as some guidance needs to be provided for specific cases. Restored config/policyLogger.properties file. It was modified by a junit test. Change-Id: I49fee98b2497d9d503d81bbbacbb1b416e1058a7 Signed-off-by: Magnusen, Drew (dm741q) <dm741q@att.com>
Diffstat (limited to 'common-logging')
-rw-r--r--common-logging/config/policyLogger.properties2
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/ONAPLoggingContext.java56
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/ONAPLoggingUtils.java2
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java2
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java4
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java4
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java2
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java6
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java2
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/eelf/PolicyLogger.java92
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java30
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTester.java2
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java34
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/SharedContext.java2
-rw-r--r--common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/Slf4jLoggingContext.java8
15 files changed, 87 insertions, 161 deletions
diff --git a/common-logging/config/policyLogger.properties b/common-logging/config/policyLogger.properties
index 1feed375..8e4e869a 100644
--- a/common-logging/config/policyLogger.properties
+++ b/common-logging/config/policyLogger.properties
@@ -41,4 +41,4 @@ metricsLogger.level=ON
# Set level for error file. Set OFF to disable; set ON to enable
error.level=ON
# Set level for audit file. Set OFF to disable; set ON to enable
-audit.level=ON
+audit.level=ON \ No newline at end of file
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/ONAPLoggingContext.java b/common-logging/src/main/java/org/onap/policy/common/logging/ONAPLoggingContext.java
index bbaf2e0e..3932f426 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/ONAPLoggingContext.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/ONAPLoggingContext.java
@@ -20,9 +20,6 @@
package org.onap.policy.common.logging;
-//import static org.onap.policy.common.logging.eelf.Configuration.TRANSACTION_BEGIN_TIME_STAMP;
-//import static org.onap.policy.common.logging.eelf.Configuration.TRANSACTION_ELAPSED_TIME;
-//import static org.onap.policy.common.logging.eelf.Configuration.TRANSACTION_END_TIME_STAMP;
import java.text.SimpleDateFormat;
import java.time.Duration;
@@ -88,7 +85,6 @@ public class ONAPLoggingContext {
private static LoggingContextFactory.Builder loggingContextBuilder = new LoggingContextFactory.Builder();
protected SharedLoggingContext context = null;
-// private long transactionStartTime = 0;
private Instant transactionStartTime;
private Instant metricStartTime;
@@ -132,7 +128,6 @@ public class ONAPLoggingContext {
* the duration of the transaction.
*/
public void transactionStarted() {
-// transactionStartTime = System.currentTimeMillis();
transactionStartTime = Instant.now();
setTransactionBeginTimestamp(transactionStartTime);
}
@@ -154,7 +149,6 @@ public class ONAPLoggingContext {
* the duration of the metric.
*/
public void metricStarted() {
-// transactionStartTime = System.currentTimeMillis();
metricStartTime = Instant.now();
setMetricBeginTimestamp(metricStartTime);
}
@@ -419,32 +413,6 @@ public class ONAPLoggingContext {
return context.get(CLASSNAME, "");
}
- /**
- * Set the value for the data item with key "timer".
- * An alternative to calling this method directly is to call
- * <code>transactionStarted()</code> at the start of transaction
- * processing and <code>transactionEnded()</code> at the end,
- * which will compute the time difference in milliseconds
- * and store the result as the "timer" value.
- *
- * @param id
- */
-// public void setTimer(Long timer) {
-// context.put(TIMER, timer);
-// }
-
-// public void setTimer(Long elapsedtime) {
-// String unit = " milliseconds";
-// context.put(TRANSACTION_ELAPSED_TIME, elapsedtime + unit);
-// }
-
- /**
- * Get the value for the data item with key "timer"
- * @return current value, or 0 if not set
- */
-// public long getTimer() {
-// return context.get(TRANSACTION_ELAPSED_TIME, 0);
-// }
/**
* Set the value for the data item with key "TransactionBeginTimestamp"
@@ -499,16 +467,8 @@ public class ONAPLoggingContext {
public void setTransactionElapsedTime(Instant transactionEndTime) {
long ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
- //String unit = " Seconds";
- //if(ns == 1){
- //unit = " Second";
- //}
-
- //if(ns < 1){
- //ns = Duration.between(transactionStartTime, transactionEndTime).toMillis();
- //unit = " milliseconds";
- //}
- context.put(TRANSACTION_ELAPSED_TIME, ns); // + unit);
+
+ context.put(TRANSACTION_ELAPSED_TIME, ns);
}
/**
@@ -572,16 +532,8 @@ public class ONAPLoggingContext {
public void setMetricElapsedTime(Instant metricEndTime) {
long ns = Duration.between(metricStartTime, metricEndTime).toMillis();
- //String unit = " Seconds";
- //if(ns == 1){
- //unit = " Second";
- //}
-
- //if(ns < 1){
- //ns = Duration.between(metricStartTime, metricEndTime).toMillis();
- //unit = " milliseconds";
- //}
- context.put(METRIC_ELAPSED_TIME, ns); // + unit);
+
+ context.put(METRIC_ELAPSED_TIME, ns);
}
/**
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/ONAPLoggingUtils.java b/common-logging/src/main/java/org/onap/policy/common/logging/ONAPLoggingUtils.java
index b4d4d8d2..e0778ea3 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/ONAPLoggingUtils.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/ONAPLoggingUtils.java
@@ -24,6 +24,8 @@ import javax.servlet.http.HttpServletRequest;
public class ONAPLoggingUtils {
+ private ONAPLoggingUtils() {};
+
public static ONAPLoggingContext getLoggingContextForRequest(HttpServletRequest request,
ONAPLoggingContext baseContext)
{
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java
index 01fc0ddd..7b9bba65 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/DroolsPDPMDCInfo.java
@@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentHashMap;
public class DroolsPDPMDCInfo implements MDCInfo{
- private static ConcurrentHashMap<String, String> mdcMap = new ConcurrentHashMap<String, String>();
+ private static ConcurrentHashMap<String, String> mdcMap = new ConcurrentHashMap<>();
static {
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java
index cbb8c7a3..1fce4791 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/ErrorCodeMap.java
@@ -30,7 +30,7 @@ import java.util.HashMap;
public class ErrorCodeMap {
- public static HashMap<MessageCodes, ErrorCodeInfo> hm = new HashMap<MessageCodes, ErrorCodeInfo>();
+ protected static final HashMap<MessageCodes, ErrorCodeInfo> hm = new HashMap<>();
private static String ERROR_PERMISSIONS = "POLICY-100E";
private static String ERROR_PERMISSIONS_DESCRIPTION = "This is a Permissions Error. Please check the error message for detail information";
@@ -79,7 +79,7 @@ public class ErrorCodeMap {
hm.put(MessageCodes.ERROR_UNKNOWN, new ErrorCodeInfo(ERROR_UNKNOWN, ERROR_UNKNOWN_DESCRIPTION));
hm.put(MessageCodes.ERROR_AUDIT, new ErrorCodeInfo(ERROR_AUDIT, ERROR_AUDIT_DESCRIPTION));
}
-
+ private ErrorCodeMap() {};
static class ErrorCodeInfo {
private String errorCode;
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java
index 2aaa1146..2267b909 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventData.java
@@ -33,6 +33,9 @@ public class EventData {
private Instant startTime = null;
private Instant endTime = null;
+ //Default constructor takes no arguments.
+ //Is empty because instance variables are assigned
+ //their default values upon declaration.
public EventData() {
}
@@ -68,6 +71,7 @@ public class EventData {
this.endTime = endTime;
}
+ @Override
public String toString(){
return requestID + " Starting Time : " + this.startTime + " Ending Time : " + this.endTime;
}
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java
index 7e4d45d8..58699867 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfo.java
@@ -37,7 +37,7 @@ public class EventTrackInfo {
* Load factor of 0,9 ensures a dense packaging inside ConcurrentHashMap which will optimize memory use
* ConcurencyLevel set to 1 will ensure that only one shard is created and maintained
*/
- eventInfo = new ConcurrentHashMap<String, EventData>(16, 0.9f, 1);
+ eventInfo = new ConcurrentHashMap<>(16, 0.9f, 1);
}
/**
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java
index d0a7cc16..8dc7ecb0 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/EventTrackInfoHandler.java
@@ -56,8 +56,8 @@ public class EventTrackInfoHandler extends TimerTask {
return;
}
- Instant startTime = null;
- long ns = 0;
+ Instant startTime;
+ long ns;
ArrayList<String> expiredEvents = null;
@@ -76,7 +76,7 @@ public class EventTrackInfoHandler extends TimerTask {
if (ns > PolicyLogger.EXPIRED_TIME){
if (expiredEvents == null) {
- expiredEvents = new ArrayList<String>();
+ expiredEvents = new ArrayList<>();
}
expiredEvents.add(key);
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java
index fc44dcff..d57ed0c4 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/eelf/MDCInfo.java
@@ -27,7 +27,7 @@ import java.util.concurrent.ConcurrentHashMap;
* Interface needs to be implemented by DroolsPDPMDCInfo
*
*/
-
+@FunctionalInterface
public interface MDCInfo {
public ConcurrentHashMap<String, String> getMDCInfo();
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 7507c9ea..e2ab31c8 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
@@ -121,7 +121,7 @@ public class PolicyLogger {
transId = UUID.randomUUID().toString();
}
- if(component != null && component.equalsIgnoreCase("DROOLS")){
+ if("DROOLS".equalsIgnoreCase(component)){
MDC.put(TARGET_ENTITY, "POLICY");
MDC.put(TARGET_SERVICE_NAME, "drools evaluate rule");
return postMDCInfoForEvent(transId, new DroolsPDPMDCInfo());
@@ -144,15 +144,7 @@ public class PolicyLogger {
Instant startTime = Instant.now();
Instant endTime = Instant.now();
long ns = Duration.between(startTime, endTime).toMillis(); // use millisecond as default and remove unit from log
- //String unit = " Seconds";
- //if(ns == 1){
- //unit = " Second";
- //}
-
- //if(ns < 1){
- //ns = Duration.between(startTime, endTime).toMillis();
- //unit = " milliseconds";
- //}
+
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
@@ -164,7 +156,7 @@ public class PolicyLogger {
//set default values for these required fields below, they can be overridden
formatedTime = sdf.format(Date.from(endTime));
MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns));
MDC.put(PARTNER_NAME, "N/A");
@@ -190,7 +182,7 @@ public class PolicyLogger {
ConcurrentHashMap<String, String> mdcMap = mdcInfo.getMDCInfo();
Iterator<String> keyIterator = mdcMap.keySet().iterator();
- String key = "";
+ String key;
while(keyIterator.hasNext()){
key = keyIterator.next();
@@ -207,15 +199,6 @@ public class PolicyLogger {
Instant startTime = Instant.now();
Instant endTime = Instant.now();
long ns = Duration.between(startTime, endTime).toMillis(); // use millisecond as default and remove unit from log
- //String unit = " Seconds";
- //if(ns == 1){
- //unit = " Second";
- //}
-
- //if(ns < 1){
- //ns = Duration.between(startTime, endTime).toMillis();
- //unit = " milliseconds";
- //}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+00:00");
@@ -225,7 +208,7 @@ public class PolicyLogger {
//set default values for these required fields below, they can be overridden
formatedTime = sdf.format(Date.from(endTime));
MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns));
return transId;
}
@@ -238,15 +221,7 @@ public class PolicyLogger {
Instant startTime = Instant.now();
Instant endTime = Instant.now();
long ns = Duration.between(startTime, endTime).toMillis();
- //String unit = " Seconds";
- //if(ns == 1){
- //unit = " Second";
- //}
-
- //if(ns < 1){
- //ns = Duration.between(startTime, endTime).toMillis();
- //unit = " milliseconds";
- //}
+
MDC.put(MDC_INSTANCE_UUID, "");
MDC.put(MDC_ALERT_SEVERITY, "");
@@ -258,7 +233,7 @@ public class PolicyLogger {
//set default values for these required fields below, they can be overridden
formatedTime = sdf.format(Date.from(endTime));
MDC.put(END_TIME_STAMP, formatedTime);
- MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns));
MDC.put(PARTNER_NAME, "N/A");
@@ -770,11 +745,9 @@ public class PolicyLogger {
isEventTrackerRunning = true;
}
- }else if( size <= STOP_CHECK_POINT){
+ }else if( size <= STOP_CHECK_POINT && isEventTrackerRunning){
- if(isEventTrackerRunning){
- stopCleanUp();
- }
+ stopCleanUp();
}
}
@@ -951,27 +924,18 @@ public class PolicyLogger {
MDC.put(RESPONSE_DESCRIPTION, "N/A");
long ns = Duration.between(startTime, endTime).toMillis();
- //String unit = " Seconds";
- //if(ns == 1){
- //unit = " Second";
- //}
- //if(ns < 1){
- //ns = Duration.between(startTime, endTime).toMillis();
- //unit = " milliseconds";
- //}
-
- MDC.put(ELAPSED_TIME, Long.toString(ns)); // + unit);
+ MDC.put(ELAPSED_TIME, Long.toString(ns));
auditLogger.info(MessageCodes.RULE_AUDIT_START_END_INFO,
serviceName, rule, startTime.toString(), endTime.toString(), Long.toString(ns), policyVersion);
//--- remove the record from the concurrentHashMap
- if(eventTracker != null){
- if(eventTracker.getEventDataByRequestID(eventId) != null){
- eventTracker.remove(eventId);
- debugLogger.info("eventTracker.remove(" + eventId + ")");
- }
+ if(eventTracker != null && eventTracker.getEventDataByRequestID(eventId) != null){
+
+ eventTracker.remove(eventId);
+ debugLogger.info("eventTracker.remove(" + eventId + ")");
+
}
}
@@ -1089,7 +1053,7 @@ public class PolicyLogger {
PrintWriter pw = new PrintWriter(sw);
t.printStackTrace(pw);
String newStValue = sw.toString().replace ('|', '!').replace ("\n", " - ");
- int curSize = (arguments == null ? 0 : arguments.length);
+ int curSize = arguments == null ? 0 : arguments.length;
StringBuffer newArgument = new StringBuffer();
for(int i=0; i<curSize; i++) {
newArgument.append(arguments[i]);
@@ -1151,11 +1115,11 @@ public class PolicyLogger {
// fetch and verify definitions of some properties
try{
- int timerDelayTime = Integer.parseInt(loggerProperties.getProperty("timer.delay.time", ""+1000));
- int checkInterval = Integer.parseInt(loggerProperties.getProperty("check.interval", ""+30000));
- int expiredDate = Integer.parseInt(loggerProperties.getProperty("event.expired.time",""+86400));
- int concurrentHashMapLimit = Integer.parseInt(loggerProperties.getProperty("concurrentHashMap.limit", ""+5000));
- int stopCheckPoint = Integer.parseInt(loggerProperties.getProperty("stop.check.point",""+2500));
+ int timerDelayTime = Integer.parseInt(loggerProperties.getProperty("timer.delay.time", Integer.toString(1000)));
+ int checkInterval = Integer.parseInt(loggerProperties.getProperty("check.interval", Integer.toString(30000)));
+ int expiredDate = Integer.parseInt(loggerProperties.getProperty("event.expired.time", Integer.toString(86400)));
+ int concurrentHashMapLimit = Integer.parseInt(loggerProperties.getProperty("concurrentHashMap.limit", Integer.toString(5000)));
+ int stopCheckPoint = Integer.parseInt(loggerProperties.getProperty("stop.check.point", Integer.toString(2500)));
String loggerType = loggerProperties.getProperty("logger.type",logger_type.toString());
String debugLevel = loggerProperties.getProperty("debugLogger.level","INFO");
@@ -1166,7 +1130,7 @@ public class PolicyLogger {
String overrideLogbackLevel = loggerProperties.getProperty("override.logback.level.setup");
if(overrideLogbackLevel != null && !overrideLogbackLevel.isEmpty()) {
- if(overrideLogbackLevel.equalsIgnoreCase("TRUE")){
+ if("TRUE".equalsIgnoreCase(overrideLogbackLevel)){
isOverrideLogbackLevel = true;
}else{
isOverrideLogbackLevel = false;
@@ -1295,15 +1259,15 @@ public class PolicyLogger {
if (loggerType != null){
- if (loggerType.equalsIgnoreCase("EELF")){
+ if ("EELF".equalsIgnoreCase(loggerType)){
logger_type = LoggerType.EELF;
- }else if (loggerType.equalsIgnoreCase("LOG4J")){
+ }else if ("LOG4J".equalsIgnoreCase(loggerType)){
logger_type = LoggerType.LOG4J;
- }else if (loggerType.equalsIgnoreCase("SYSTEMOUT")){
+ }else if ("SYSTEMOUT".equalsIgnoreCase(loggerType)){
logger_type = LoggerType.SYSTEMOUT;
@@ -1368,7 +1332,7 @@ public class PolicyLogger {
public static void setErrorLevel(String errorLevel){
if(isOverrideLogbackLevel){
- if(errorLevel != null && errorLevel.equalsIgnoreCase("OFF")){
+ if("OFF".equalsIgnoreCase(errorLevel)){
PolicyLogger.ERROR_LEVEL = Level.OFF;
errorLogger.setLevel(ERROR_LEVEL);
}else{
@@ -1385,7 +1349,7 @@ public class PolicyLogger {
public static void setMetricsLevel(String metricsLevel){
if(isOverrideLogbackLevel){
- if(metricsLevel != null && metricsLevel.equalsIgnoreCase("OFF")){
+ if("OFF".equalsIgnoreCase(metricsLevel)){
PolicyLogger.METRICS_LEVEL = Level.OFF;
metricsLogger.setLevel(METRICS_LEVEL);
}else {
@@ -1403,7 +1367,7 @@ public class PolicyLogger {
public static void setAuditLevel(String auditLevel){
if(isOverrideLogbackLevel){
- if(auditLevel != null && auditLevel.equalsIgnoreCase("OFF")){
+ if("OFF".equalsIgnoreCase(auditLevel)){
PolicyLogger.AUDIT_LEVEL = Level.OFF;
auditLogger.setLevel(AUDIT_LEVEL);
}else {
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java
index 797f857b..2cf591cb 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLogger.java
@@ -39,9 +39,9 @@ import org.onap.policy.common.logging.flexlogger.PropertyUtil.Listener;
public class FlexLogger extends SecurityManager{
private static LoggerType loggerType = LoggerType.EELF;
- private static ConcurrentHashMap<String, Logger4J> logger4JMap = new ConcurrentHashMap<String, Logger4J>();
- private static ConcurrentHashMap<String, EelfLogger> eelfLoggerMap = new ConcurrentHashMap<String, EelfLogger>();
- private static ConcurrentHashMap<String, SystemOutLogger> systemOutMap = new ConcurrentHashMap<String, SystemOutLogger>();
+ private static ConcurrentHashMap<String, Logger4J> logger4JMap = new ConcurrentHashMap<>();
+ private static ConcurrentHashMap<String, EelfLogger> eelfLoggerMap = new ConcurrentHashMap<>();
+ private static ConcurrentHashMap<String, SystemOutLogger> systemOutMap = new ConcurrentHashMap<>();
//--- init logger first
static {
loggerType = initlogger();
@@ -60,10 +60,10 @@ public class FlexLogger extends SecurityManager{
logger = getEelfLogger(clazz, false);
break;
case LOG4J:
- logger = getLog4JLogger(clazz);
+ logger = getLog4JLogger();
break;
case SYSTEMOUT:
- logger = getSystemOutLogger(null);
+ logger = getSystemOutLogger();
break;
}
@@ -87,7 +87,7 @@ public class FlexLogger extends SecurityManager{
logger = getLog4JLogger(s);
break;
case SYSTEMOUT:
- logger = getSystemOutLogger(null);
+ logger = getSystemOutLogger();
break;
}
@@ -109,10 +109,10 @@ public class FlexLogger extends SecurityManager{
logger = getEelfLogger(clazz, isNewTransaction);
break;
case LOG4J:
- logger = getLog4JLogger(clazz);
+ logger = getLog4JLogger();
break;
case SYSTEMOUT:
- logger = getSystemOutLogger(null);
+ logger = getSystemOutLogger();
break;
}
@@ -137,7 +137,7 @@ public class FlexLogger extends SecurityManager{
logger = getLog4JLogger(s);
break;
case SYSTEMOUT:
- logger = getSystemOutLogger(null);
+ logger = getSystemOutLogger();
break;
}
@@ -156,7 +156,7 @@ public class FlexLogger extends SecurityManager{
* Returns an instance of Logger4J
* @param clazz
*/
- private static Logger4J getLog4JLogger(Class<?> clazz){
+ private static Logger4J getLog4JLogger(){
String className = new FlexLogger().getClassName();
if(!logger4JMap.containsKey(className)){
@@ -190,8 +190,8 @@ public class FlexLogger extends SecurityManager{
*/
private static EelfLogger getEelfLogger(Class<?> clazz, boolean isNewTransaction){
- String className = "";
- EelfLogger logger = null;
+ String className;
+ EelfLogger logger;
if(clazz != null){
className = clazz.getName();
}else{
@@ -221,7 +221,7 @@ public class FlexLogger extends SecurityManager{
* Returns an instance of SystemOutLogger
* @param clazz
*/
- private static SystemOutLogger getSystemOutLogger(Class<?> clazz){
+ private static SystemOutLogger getSystemOutLogger(){
String className = new FlexLogger().getClassName();
@@ -253,8 +253,7 @@ public class FlexLogger extends SecurityManager{
if (loggerTypeString != null){
if (loggerTypeString.equalsIgnoreCase("EELF")){
loggerType = LoggerType.EELF;
- if (overrideLogbackLevel != null &&
- overrideLogbackLevel.equalsIgnoreCase("TRUE")) {
+ if ("TRUE".equalsIgnoreCase(overrideLogbackLevel)) {
System.out.println("FlexLogger: start listener.");
properties = PropertyUtil.getProperties
("config/policyLogger.properties",
@@ -292,6 +291,7 @@ public class FlexLogger extends SecurityManager{
/**
* This method will be called automatically if he policyLogger.properties got updated
*/
+ @Override
public void propertiesChanged(Properties properties,
Set<String> changedKeys) {
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTester.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTester.java
index eddece12..ff33c299 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTester.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/FlexLoggerTester.java
@@ -30,8 +30,6 @@ public class FlexLoggerTester {
// get an instance of logger
Logger logger = FlexLogger.getLogger(FlexLoggerTester.class);
- //logger.info("this is a testing of FlexLogger with logger type:" + FlexLogger.loggerType);
-
logger.info("logger.isAuditEnabled():" + logger.isAuditEnabled());
logger.info("logger.isDebugEnabled():" + logger.isDebugEnabled());
logger.info("logger.isErrorEnabled():" + logger.isErrorEnabled());
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java
index 598dd09b..d2a98239 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/PropertyUtil.java
@@ -56,7 +56,7 @@ public class PropertyUtil
// load properties (may throw an IOException)
rval.load(fis);
- return(rval);
+ return rval;
}
finally
{
@@ -75,7 +75,7 @@ public class PropertyUtil
*/
static public Properties getProperties(String fileName) throws IOException
{
- return(getProperties(new File(fileName)));
+ return getProperties(new File(fileName));
}
/* ============================================================ */
@@ -87,6 +87,7 @@ public class PropertyUtil
* This is the callback interface, used for sending notifications of
* changes in the properties file.
*/
+ @FunctionalInterface
public interface Listener
{
/**
@@ -100,7 +101,7 @@ public class PropertyUtil
// this table maps canonical file into a 'ListenerRegistration' instance
static private HashMap<File, ListenerRegistration> registrations =
- new HashMap<File, ListenerRegistration>();
+ new HashMap<>();
/**
* This is an internal class - one instance of this exists for each
@@ -141,7 +142,7 @@ public class PropertyUtil
properties = getProperties(file);
// no listeners yet
- listeners = new LinkedList<Listener>();
+ listeners = new LinkedList<>();
// add to static table, so this instance can be shared
registrations.put(file, this);
@@ -163,6 +164,7 @@ public class PropertyUtil
// create and schedule the timer task, so this is periodically polled
timerTask = new TimerTask()
{
+ @Override
public void run()
{
try
@@ -186,7 +188,7 @@ public class PropertyUtil
synchronized Properties addListener(Listener listener)
{
listeners.add(listener);
- return((Properties)properties.clone());
+ return (Properties)properties.clone();
}
/**
@@ -203,7 +205,7 @@ public class PropertyUtil
// one is being removed.
synchronized(registrations)
{
- if (listeners.size() == 0)
+ if (listeners.isEmpty())
{
timerTask.cancel();
registrations.remove(file);
@@ -226,7 +228,7 @@ public class PropertyUtil
// Save old set, and initial set of changed properties.
Properties oldProperties = properties;
HashSet<String> changedProperties =
- new HashSet<String>(oldProperties.stringPropertyNames());
+ new HashSet<>(oldProperties.stringPropertyNames());
// Fetch the list of listeners that we will potentially notify,
// and the new properties. Note that this is in a 'synchronized'
@@ -259,7 +261,7 @@ public class PropertyUtil
}
// 'changedProperties' should be correct at this point
- if (changedProperties.size() != 0)
+ if (!changedProperties.isEmpty())
{
// there were changes - notify everyone in 'listeners'
for (final Listener notify : listeners)
@@ -269,12 +271,13 @@ public class PropertyUtil
final Properties tmpProperties =
(Properties)(properties.clone());
final HashSet<String> tmpChangedProperties =
- new HashSet<String>(changedProperties);
+ new HashSet<>(changedProperties);
// Do the notification in a separate thread, so blocking
// won't cause any problems.
new Thread()
{
+ @Override
public void run()
{
notify.propertiesChanged
@@ -309,25 +312,25 @@ public class PropertyUtil
if (listener == null)
{
// no listener specified -- just fetch the properties
- return(getProperties(file));
+ return getProperties(file);
}
// Convert the file to a canonical form in order to avoid the situation
// where different names refer to the same file.
- file = file.getCanonicalFile();
+ File tempFile = file.getCanonicalFile();
// See if there is an existing registration. The 'synchronized' block
// is needed to handle the case where a new listener is added at about
// the same time that another one is being removed.
synchronized(registrations)
{
- ListenerRegistration reg = registrations.get(file);
+ ListenerRegistration reg = registrations.get(tempFile);
if (reg == null)
{
// a new registration is needed
- reg = new ListenerRegistration(file);
+ reg = new ListenerRegistration(tempFile);
}
- return(reg.addListener(listener));
+ return reg.addListener(listener);
}
}
@@ -350,7 +353,7 @@ public class PropertyUtil
static public Properties getProperties(String fileName, Listener listener)
throws IOException
{
- return(getProperties(new File(fileName), listener));
+ return getProperties(new File(fileName), listener);
}
/**
@@ -394,6 +397,7 @@ public class PropertyUtil
this.name = name;
}
+ @Override
public void propertiesChanged(Properties properties, Set<String> changedKeys)
{
System.out.println("Test(" + name + ")\nproperties = " + properties
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/SharedContext.java b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/SharedContext.java
index 715edfab..7f4a1096 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/SharedContext.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/SharedContext.java
@@ -35,7 +35,7 @@ public class SharedContext extends Slf4jLoggingContext implements SharedLoggingC
public SharedContext ( LoggingContext base )
{
super ( base );
- fMap = new HashMap<String,String> ();
+ fMap = new HashMap<> ();
}
@Override
diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/Slf4jLoggingContext.java b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/Slf4jLoggingContext.java
index 187b2954..628d4b9e 100644
--- a/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/Slf4jLoggingContext.java
+++ b/common-logging/src/main/java/org/onap/policy/common/logging/nsa/impl/Slf4jLoggingContext.java
@@ -40,12 +40,13 @@ public class Slf4jLoggingContext implements LoggingContext
MDC.put ( key, value );
}
+ @Override
public void put ( String key, long value )
{
- put ( key, "" + value );
+ put ( key, Long.toString(value));
}
-
+ @Override
public String get ( String key, String defaultValue )
{
String result = MDC.get ( key );
@@ -56,9 +57,10 @@ public class Slf4jLoggingContext implements LoggingContext
return result;
}
+ @Override
public long get ( String key, long defaultValue )
{
- final String str = get ( key, "" + defaultValue );
+ final String str = get ( key, Long.toString(defaultValue));
try
{
return Long.parseLong ( str );