소스 검색

HADOOP-15377. Improve debug messages in MetricsConfig.java

Signed-off-by: Akira Ajisaka <aajisaka@apache.org>
BELUGA BEHR 7 년 전
부모
커밋
33768724ff
1개의 변경된 파일30개의 추가작업 그리고 20개의 파일을 삭제
  1. 30 20
      hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java

+ 30 - 20
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/metrics2/impl/MetricsConfig.java

@@ -118,20 +118,23 @@ class MetricsConfig extends SubsetConfiguration {
                 .setListDelimiterHandler(new DefaultListDelimiterHandler(',')))
                 .setListDelimiterHandler(new DefaultListDelimiterHandler(',')))
               .getConfiguration()
               .getConfiguration()
               .interpolatedConfiguration();
               .interpolatedConfiguration();
-        LOG.info("loaded properties from "+ fname);
-        LOG.debug(toString(cf));
+        LOG.info("Loaded properties from {}", fname);
+        if (LOG.isDebugEnabled()) {
+          LOG.debug("Properties: {}", toString(cf));
+        }
         MetricsConfig mc = new MetricsConfig(cf, prefix);
         MetricsConfig mc = new MetricsConfig(cf, prefix);
-        LOG.debug(mc.toString());
+        LOG.debug("Metrics Config: {}", mc);
         return mc;
         return mc;
       } catch (ConfigurationException e) {
       } catch (ConfigurationException e) {
         // Commons Configuration defines the message text when file not found
         // Commons Configuration defines the message text when file not found
         if (e.getMessage().startsWith("Could not locate")) {
         if (e.getMessage().startsWith("Could not locate")) {
+          LOG.debug("Could not locate file {}", fname, e);
           continue;
           continue;
         }
         }
         throw new MetricsConfigException(e);
         throw new MetricsConfigException(e);
       }
       }
     }
     }
-    LOG.warn("Cannot locate configuration: tried "+
+    LOG.warn("Cannot locate configuration: tried " +
              Joiner.on(",").join(fileNames));
              Joiner.on(",").join(fileNames));
     // default to an empty configuration
     // default to an empty configuration
     return new MetricsConfig(new PropertiesConfiguration(), prefix);
     return new MetricsConfig(new PropertiesConfiguration(), prefix);
@@ -168,7 +171,6 @@ class MetricsConfig extends SubsetConfiguration {
 
 
   Iterable<String> keys() {
   Iterable<String> keys() {
     return new Iterable<String>() {
     return new Iterable<String>() {
-      @SuppressWarnings("unchecked")
       @Override
       @Override
       public Iterator<String> iterator() {
       public Iterator<String> iterator() {
         return (Iterator<String>) getKeys();
         return (Iterator<String>) getKeys();
@@ -186,21 +188,21 @@ class MetricsConfig extends SubsetConfiguration {
     Object value = super.getPropertyInternal(key);
     Object value = super.getPropertyInternal(key);
     if (value == null) {
     if (value == null) {
       if (LOG.isDebugEnabled()) {
       if (LOG.isDebugEnabled()) {
-        LOG.debug("poking parent '"+ getParent().getClass().getSimpleName() +
-                  "' for key: "+ key);
+        LOG.debug("poking parent '" + getParent().getClass().getSimpleName() +
+                  "' for key: " + key);
       }
       }
       return getParent().getProperty(key.startsWith(PREFIX_DEFAULT) ? key
       return getParent().getProperty(key.startsWith(PREFIX_DEFAULT) ? key
                                      : PREFIX_DEFAULT + key);
                                      : PREFIX_DEFAULT + key);
     }
     }
-    if (LOG.isDebugEnabled()) {
-      LOG.debug("returning '"+ value +"' for key: "+ key);
-    }
+    LOG.debug("Returning '{}' for key: {}", value, key);
     return value;
     return value;
   }
   }
 
 
   <T extends MetricsPlugin> T getPlugin(String name) {
   <T extends MetricsPlugin> T getPlugin(String name) {
     String clsName = getClassName(name);
     String clsName = getClassName(name);
-    if (clsName == null) return null;
+    if (clsName == null) {
+      return null;
+    }
     try {
     try {
       Class<?> cls = Class.forName(clsName, true, getPluginLoader());
       Class<?> cls = Class.forName(clsName, true, getPluginLoader());
       @SuppressWarnings("unchecked")
       @SuppressWarnings("unchecked")
@@ -213,9 +215,9 @@ class MetricsConfig extends SubsetConfiguration {
   }
   }
 
 
   String getClassName(String prefix) {
   String getClassName(String prefix) {
-    String classKey = prefix.isEmpty() ? "class" : prefix +".class";
+    String classKey = prefix.isEmpty() ? "class" : prefix.concat(".class");
     String clsName = getString(classKey);
     String clsName = getString(classKey);
-    LOG.debug(clsName);
+    LOG.debug("Class name for prefix {} is {}", prefix, clsName);
     if (clsName == null || clsName.isEmpty()) {
     if (clsName == null || clsName.isEmpty()) {
       return null;
       return null;
     }
     }
@@ -223,25 +225,29 @@ class MetricsConfig extends SubsetConfiguration {
   }
   }
 
 
   ClassLoader getPluginLoader() {
   ClassLoader getPluginLoader() {
-    if (pluginLoader != null) return pluginLoader;
+    if (pluginLoader != null) {
+      return pluginLoader;
+    }
     final ClassLoader defaultLoader = getClass().getClassLoader();
     final ClassLoader defaultLoader = getClass().getClassLoader();
     Object purls = super.getProperty(PLUGIN_URLS_KEY);
     Object purls = super.getProperty(PLUGIN_URLS_KEY);
-    if (purls == null) return defaultLoader;
+    if (purls == null) {
+      return defaultLoader;
+    }
     Iterable<String> jars = SPLITTER.split((String) purls);
     Iterable<String> jars = SPLITTER.split((String) purls);
     int len = Iterables.size(jars);
     int len = Iterables.size(jars);
-    if ( len > 0) {
+    if (len > 0) {
       final URL[] urls = new URL[len];
       final URL[] urls = new URL[len];
       try {
       try {
         int i = 0;
         int i = 0;
         for (String jar : jars) {
         for (String jar : jars) {
-          LOG.debug(jar);
+          LOG.debug("Parsing URL for {}", jar);
           urls[i++] = new URL(jar);
           urls[i++] = new URL(jar);
         }
         }
       } catch (Exception e) {
       } catch (Exception e) {
         throw new MetricsConfigException(e);
         throw new MetricsConfigException(e);
       }
       }
       if (LOG.isDebugEnabled()) {
       if (LOG.isDebugEnabled()) {
-        LOG.debug("using plugin jars: "+ Iterables.toString(jars));
+        LOG.debug("Using plugin jars: {}", Iterables.toString(jars));
       }
       }
       pluginLoader = doPrivileged(new PrivilegedAction<ClassLoader>() {
       pluginLoader = doPrivileged(new PrivilegedAction<ClassLoader>() {
         @Override public ClassLoader run() {
         @Override public ClassLoader run() {
@@ -259,9 +265,13 @@ class MetricsConfig extends SubsetConfiguration {
   MetricsFilter getFilter(String prefix) {
   MetricsFilter getFilter(String prefix) {
     // don't create filter instances without out options
     // don't create filter instances without out options
     MetricsConfig conf = subset(prefix);
     MetricsConfig conf = subset(prefix);
-    if (conf.isEmpty()) return null;
+    if (conf.isEmpty()) {
+      return null;
+    }
     MetricsFilter filter = getPlugin(prefix);
     MetricsFilter filter = getPlugin(prefix);
-    if (filter != null) return filter;
+    if (filter != null) {
+      return filter;
+    }
     // glob filter is assumed if pattern is specified but class is not.
     // glob filter is assumed if pattern is specified but class is not.
     filter = new GlobFilter();
     filter = new GlobFilter();
     filter.init(conf);
     filter.init(conf);