Refactor property logging
[appc.git] / appc-core / appc-common-bundle / src / main / java / org / onap / appc / configuration / ConfigurationFactory.java
index 9ea5083..9570025 100644 (file)
@@ -36,6 +36,7 @@ import java.util.Properties;
 import java.util.concurrent.locks.ReentrantReadWriteLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock;
 import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock;
+import org.apache.commons.lang3.StringUtils;
 import org.onap.appc.i18n.Msg;
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
@@ -266,6 +267,16 @@ public final class ConfigurationFactory {
         return local;
     }
 
+    private static void logPropertyValue(String key, String value) {
+        if ((!StringUtils.containsIgnoreCase(key, "pass")) && (!StringUtils.containsIgnoreCase(key, "secret"))) {
+            logger.info(Msg.PROPERTY_VALUE, key, value);
+        } else if (logger.isDebugEnabled()) {
+            logger.debug(Msg.PROPERTY_VALUE, key, value);
+        } else {
+            logger.info(Msg.PROPERTY_VALUE, key, value.replaceAll(".", "*"));
+        }
+    }
+
     /**
      * This method will clear the current configuration and then re-initialize it with the default
      * values, application-specific configuration file, user-supplied properties (if any), and then
@@ -312,7 +323,7 @@ public final class ConfigurationFactory {
                 }
             }
             for (String key : config.getProperties().stringPropertyNames()) {
-                logger.info(Msg.PROPERTY_VALUE, key, config.getProperty(key));
+                logPropertyValue(key, config.getProperty(key));
             }
         } else {
             logger.info(Msg.NO_DEFAULTS_FOUND, DEFAULT_PROPERTIES);
@@ -359,7 +370,7 @@ public final class ConfigurationFactory {
                     stream = new BufferedInputStream(new FileInputStream(file));
                     fileProperties.load(stream);
                     for (String key : fileProperties.stringPropertyNames()) {
-                        logger.debug(Msg.PROPERTY_VALUE, key, fileProperties.getProperty(key));
+                        logPropertyValue(key, fileProperties.getProperty(key));
                         config.setProperty(key, fileProperties.getProperty(key));
                     }
                     found = true;
@@ -388,7 +399,7 @@ public final class ConfigurationFactory {
         if (props != null) {
             logger.info(Msg.LOADING_APPLICATION_OVERRIDES);
             for (String key : props.stringPropertyNames()) {
-                logger.debug(Msg.PROPERTY_VALUE, key, props.getProperty(key));
+                logPropertyValue(key, props.getProperty(key));
                 config.setProperty(key, props.getProperty(key));
             }
         } else {