HADOOP-14706. Adding a helper method to determine whether a log is Log4j 
implement.

This closes #257

Signed-off-by: Akira Ajisaka <aajis...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/691bf5ec
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/691bf5ec
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/691bf5ec

Branch: refs/heads/HADOOP-13345
Commit: 691bf5ec5d641c0552f4b243c4efa34ec2e529dc
Parents: 35dc782
Author: wenxinhe <wenxin...@gmail.com>
Authored: Tue Aug 1 16:19:00 2017 +0800
Committer: Akira Ajisaka <aajis...@apache.org>
Committed: Fri Aug 4 14:35:57 2017 +0900

----------------------------------------------------------------------
 hadoop-common-project/hadoop-common/pom.xml          |  2 +-
 .../java/org/apache/hadoop/util/GenericsUtil.java    | 15 +++++++++++++++
 .../org/apache/hadoop/util/TestGenericsUtil.java     |  5 +++++
 3 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/691bf5ec/hadoop-common-project/hadoop-common/pom.xml
----------------------------------------------------------------------
diff --git a/hadoop-common-project/hadoop-common/pom.xml 
b/hadoop-common-project/hadoop-common/pom.xml
index ad6f734..0cd5479 100644
--- a/hadoop-common-project/hadoop-common/pom.xml
+++ b/hadoop-common-project/hadoop-common/pom.xml
@@ -179,7 +179,7 @@
     <dependency>
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-log4j12</artifactId>
-      <scope>runtime</scope>
+      <scope>compile</scope>
     </dependency>
     <dependency>
       <groupId>org.mockito</groupId>

http://git-wip-us.apache.org/repos/asf/hadoop/blob/691bf5ec/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericsUtil.java
----------------------------------------------------------------------
diff --git 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericsUtil.java
 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericsUtil.java
index 611fff9..a53096a 100644
--- 
a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericsUtil.java
+++ 
b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericsUtil.java
@@ -23,6 +23,9 @@ import java.util.List;
 
 import org.apache.hadoop.classification.InterfaceAudience;
 import org.apache.hadoop.classification.InterfaceStability;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.slf4j.impl.Log4jLoggerAdapter;
 
 /**
  * Contains utility methods for dealing with Java Generics. 
@@ -72,4 +75,16 @@ public class GenericsUtil {
     return toArray(getClass(list.get(0)), list);
   }
 
+  /**
+   * Determine whether the log of <code>clazz</code> is Log4j implementation.
+   * @param clazz a class to be determined
+   * @return true if the log of <code>clazz</code> is Log4j implementation.
+   */
+  public static boolean isLog4jLogger(Class<?> clazz) {
+    if (clazz == null) {
+      return false;
+    }
+    Logger log = LoggerFactory.getLogger(clazz);
+    return log instanceof Log4jLoggerAdapter;
+  }
 }

http://git-wip-us.apache.org/repos/asf/hadoop/blob/691bf5ec/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericsUtil.java
----------------------------------------------------------------------
diff --git 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericsUtil.java
 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericsUtil.java
index 25e2ce9..58537ad 100644
--- 
a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericsUtil.java
+++ 
b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/util/TestGenericsUtil.java
@@ -131,4 +131,9 @@ public class TestGenericsUtil extends TestCase {
             GenericClass.class, c2);
   }
 
+  public void testIsLog4jLogger() throws Exception {
+    assertFalse("False if clazz is null", GenericsUtil.isLog4jLogger(null));
+    assertTrue("The implementation is Log4j",
+        GenericsUtil.isLog4jLogger(TestGenericsUtil.class));
+  }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-commits-h...@hadoop.apache.org

Reply via email to