diff options
Diffstat (limited to 'common-logging/src/main/java/org/onap/policy/common/logging/flexlogger')
3 files changed, 34 insertions, 32 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 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 |