diff options
Diffstat (limited to 'common-logging/src/main/java/org/onap/policy/common/logging/flexlogger')
5 files changed, 42 insertions, 45 deletions
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 2cf591cb..9723755e 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 @@ -38,6 +38,7 @@ import org.onap.policy.common.logging.flexlogger.PropertyUtil.Listener; */ public class FlexLogger extends SecurityManager{ + private static final String GET_LOGGER_PREFIX = "FlexLogger:getLogger : loggerType = "; private static LoggerType loggerType = LoggerType.EELF; private static ConcurrentHashMap<String, Logger4J> logger4JMap = new ConcurrentHashMap<>(); private static ConcurrentHashMap<String, EelfLogger> eelfLoggerMap = new ConcurrentHashMap<>(); @@ -51,9 +52,9 @@ public class FlexLogger extends SecurityManager{ * Returns an instance of Logger * @param clazz */ - static public Logger getLogger(Class<?> clazz) { + public static Logger getLogger(Class<?> clazz) { Logger logger = null; - System.out.println("FlexLogger:getLogger : loggerType = " + loggerType); + System.out.println(GET_LOGGER_PREFIX + loggerType); switch (loggerType) { case EELF: @@ -75,9 +76,9 @@ public class FlexLogger extends SecurityManager{ * Returns an instance of Logger * @param s */ - static public Logger getLogger(String s) { + public static Logger getLogger(String s) { Logger logger = null; - System.out.println("FlexLogger:getLogger : loggerType = " + loggerType); + System.out.println(GET_LOGGER_PREFIX + loggerType); switch (loggerType) { case EELF: @@ -100,9 +101,9 @@ public class FlexLogger extends SecurityManager{ * @param clazz * @param isNewTransaction */ - static public Logger getLogger(Class<?> clazz, boolean isNewTransaction) { + public static Logger getLogger(Class<?> clazz, boolean isNewTransaction) { Logger logger = null; - System.out.println("FlexLogger:getLogger : loggerType = " + loggerType); + System.out.println(GET_LOGGER_PREFIX + loggerType); switch (loggerType) { case EELF: @@ -125,9 +126,9 @@ public class FlexLogger extends SecurityManager{ * @param s * @param isNewTransaction */ - static public Logger getLogger(String s, boolean isNewTransaction) { + public static Logger getLogger(String s, boolean isNewTransaction) { Logger logger = null; - System.out.println("FlexLogger:getLogger : loggerType = " + loggerType); + System.out.println(GET_LOGGER_PREFIX + loggerType); switch (loggerType) { case EELF: @@ -251,7 +252,7 @@ public class FlexLogger extends SecurityManager{ System.out.println("FlexLogger:overrideLogbackLevel => " + overrideLogbackLevel); loggerTypeString = properties.getProperty("logger.type"); if (loggerTypeString != null){ - if (loggerTypeString.equalsIgnoreCase("EELF")){ + if ("EELF".equalsIgnoreCase(loggerTypeString)){ loggerType = LoggerType.EELF; if ("TRUE".equalsIgnoreCase(overrideLogbackLevel)) { System.out.println("FlexLogger: start listener."); @@ -259,9 +260,9 @@ public class FlexLogger extends SecurityManager{ ("config/policyLogger.properties", new PropertiesCallBack("FlexLogger-CallBack")); } - }else if (loggerTypeString.equalsIgnoreCase("LOG4J")){ + }else if ("LOG4J".equalsIgnoreCase(loggerTypeString)){ loggerType = LoggerType.LOG4J; - }else if (loggerTypeString.equalsIgnoreCase("SYSTEMOUT")){ + }else if ("SYSTEMOUT".equalsIgnoreCase(loggerTypeString)){ loggerType = LoggerType.SYSTEMOUT; } @@ -281,7 +282,7 @@ public class FlexLogger extends SecurityManager{ /** * PropertiesCallBack is listening any updates on the policyLogger.properties */ - static public class PropertiesCallBack implements Listener { + public static class PropertiesCallBack implements Listener { String name; public PropertiesCallBack(String name) { 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 ff33c299..0fa65c0c 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 @@ -42,7 +42,8 @@ public class FlexLoggerTester { else logger.info("this is from logger.info call"); - if(logger.isMetricsEnabled()) logger.metrics("this is from logger.metrics call"); + if(logger.isMetricsEnabled()) + logger.metrics("this is from logger.metrics call"); logger.error("this is from logger.error call"); if(logger.isAuditEnabled()) diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger4J.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger4J.java index 9fcd47af..746012d1 100644 --- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger4J.java +++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/Logger4J.java @@ -182,12 +182,8 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge * @return boolean */ @Override - public boolean isAuditEnabled(){ - if(PolicyLogger.getAuditLevel() != null && PolicyLogger.getAuditLevel().toString().equals(Level.OFF.toString())){ - return false; - }else { - return true; - } + public boolean isAuditEnabled(){ + return !(PolicyLogger.getAuditLevel() != null && PolicyLogger.getAuditLevel().toString().equals(Level.OFF.toString())); } /** @@ -196,11 +192,7 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge */ @Override public boolean isMetricsEnabled(){ - if(PolicyLogger.getMetricsLevel() != null && PolicyLogger.getMetricsLevel().toString().equals(Level.OFF.toString())){ - return false; - }else { - return true; - } + return !(PolicyLogger.getMetricsLevel() != null && PolicyLogger.getMetricsLevel().toString().equals(Level.OFF.toString())); } /** @@ -343,12 +335,13 @@ public class Logger4J implements org.onap.policy.common.logging.flexlogger.Logge * @param transId */ @Override - public String postMDCInfoForEvent(String transId) { - if(transId == null || transId.isEmpty()){ - transId = UUID.randomUUID().toString(); + public String postMDCInfoForEvent(String transId) { + String transactionId = transId; + if(transactionId == null || transactionId.isEmpty()){ + transactionId = UUID.randomUUID().toString(); } - return transId; + return transactionId; } /** 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 d2a98239..1bc57f01 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 @@ -37,6 +37,14 @@ import java.util.TimerTask; */ public class PropertyUtil { + + // timer thread used for polling for property file changes + private static Timer timer = null; + + // this table maps canonical file into a 'ListenerRegistration' instance + private static HashMap<File, ListenerRegistration> registrations = + new HashMap<>(); + /** * Read in a properties file * @param file the properties file @@ -45,7 +53,7 @@ public class PropertyUtil * does not exist or can't be opened, and 'IOException' if there is * a problem loading the properties file. */ - static public Properties getProperties(File file) throws IOException + public static Properties getProperties(File file) throws IOException { // create an InputStream (may throw a FileNotFoundException) FileInputStream fis = new FileInputStream(file); @@ -73,16 +81,13 @@ public class PropertyUtil * does not exist or can't be opened, and 'IOException' if there is * a problem loading the properties file. */ - static public Properties getProperties(String fileName) throws IOException + public static Properties getProperties(String fileName) throws IOException { return getProperties(new File(fileName)); } /* ============================================================ */ - // timer thread used for polling for property file changes - private static Timer timer = null; - /** * This is the callback interface, used for sending notifications of * changes in the properties file. @@ -99,10 +104,6 @@ public class PropertyUtil void propertiesChanged(Properties properties, Set<String> changedKeys); } - // this table maps canonical file into a 'ListenerRegistration' instance - static private HashMap<File, ListenerRegistration> registrations = - new HashMap<>(); - /** * This is an internal class - one instance of this exists for each * property file that is being monitored. Note that multiple listeners @@ -306,7 +307,7 @@ public class PropertyUtil * does not exist or can't be opened, and 'IOException' if there is * a problem loading the properties file. */ - static public Properties getProperties(File file, Listener listener) + public static Properties getProperties(File file, Listener listener) throws IOException { if (listener == null) @@ -350,7 +351,7 @@ public class PropertyUtil * does not exist or can't be opened, and 'IOException' if there is * a problem loading the properties file. */ - static public Properties getProperties(String fileName, Listener listener) + public static Properties getProperties(String fileName, Listener listener) throws IOException { return getProperties(new File(fileName), listener); @@ -362,7 +363,7 @@ public class PropertyUtil * @param notify if not null, this is a callback interface that was used for * notifications of changes */ - static public void stopListening(File file, Listener listener) + public static void stopListening(File file, Listener listener) { if (listener != null) { @@ -380,7 +381,7 @@ public class PropertyUtil * @param notify if not null, this is a callback interface that was used for * notifications of changes */ - static public void stopListening(String fileName, Listener listener) + public static void stopListening(String fileName, Listener listener) { stopListening(new File(fileName), listener); } @@ -388,7 +389,7 @@ public class PropertyUtil /* ============================================================ */ // TEMPORARY - used to test callback interface - static public class Test implements Listener + public static class Test implements Listener { String name; diff --git a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/SystemOutLogger.java b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/SystemOutLogger.java index aeb26017..295e259a 100644 --- a/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/SystemOutLogger.java +++ b/common-logging/src/main/java/org/onap/policy/common/logging/flexlogger/SystemOutLogger.java @@ -380,11 +380,12 @@ public class SystemOutLogger implements Logger, Serializable { @Override public String postMDCInfoForEvent(String transId) { - if(transId == null || transId.isEmpty()){ - transId = UUID.randomUUID().toString(); + String transactionId = transId; + if(transactionId == null || transactionId.isEmpty()){ + transactionId = UUID.randomUUID().toString(); } - return transId; + return transactionId; } /** |