[ 
https://issues.apache.org/jira/browse/HADOOP-18653?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17697972#comment-17697972
 ] 

ASF GitHub Bot commented on HADOOP-18653:
-----------------------------------------

steveloughran commented on code in PR #5456:
URL: https://github.com/apache/hadoop/pull/5456#discussion_r1129648239


##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/log/LogLevel.java:
##########
@@ -338,14 +341,18 @@ public void doGet(HttpServletRequest request, 
HttpServletResponse response
         out.println(MARKER
             + "Submitted Class Name: <b>" + logName + "</b><br />");
 
-        Logger log = Logger.getLogger(logName);
+        org.slf4j.Logger log = LoggerFactory.getLogger(logName);
         out.println(MARKER
             + "Log Class: <b>" + log.getClass().getName() +"</b><br />");
         if (level != null) {
           out.println(MARKER + "Submitted Level: <b>" + level + "</b><br />");
         }
 
-        process(log, level, out);
+        if (GenericsUtil.isLog4jLogger(logName)) {
+          process(Logger.getLogger(logName), level, out);
+        } else {
+          out.println("Sorry, " + log.getClass() + " not supported.<br />");

Review Comment:
   text to explain "log4j loggers only"



##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericsUtil.java:
##########
@@ -89,10 +89,30 @@ public static boolean isLog4jLogger(Class<?> clazz) {
     }
     Logger log = LoggerFactory.getLogger(clazz);
     try {
-      Class log4jClass = Class.forName("org.slf4j.impl.Log4jLoggerAdapter");
+      Class<?> log4jClass = Class.forName("org.slf4j.impl.Log4jLoggerAdapter");

Review Comment:
   make this a constant string and use everywhere it is needed



##########
hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/util/GenericsUtil.java:
##########
@@ -89,10 +89,30 @@ public static boolean isLog4jLogger(Class<?> clazz) {
     }
     Logger log = LoggerFactory.getLogger(clazz);
     try {
-      Class log4jClass = Class.forName("org.slf4j.impl.Log4jLoggerAdapter");
+      Class<?> log4jClass = Class.forName("org.slf4j.impl.Log4jLoggerAdapter");
       return log4jClass.isInstance(log);
     } catch (ClassNotFoundException e) {
       return false;
     }
   }
+
+  /**
+   * Determine whether the log of the given logger is of Log4J implementation.
+   *
+   * @param logger the logger name, usually class name as string.
+   * @return true if the logger uses Log4J implementation.
+   */
+  public static boolean isLog4jLogger(String logger) {
+    if (logger == null) {
+      return false;
+    }
+    Logger log = LoggerFactory.getLogger(logger);
+    try {
+      Class<?> log4jClass = Class.forName("org.slf4j.impl.Log4jLoggerAdapter");

Review Comment:
   if the class isn't found, then that fact can be remembered in an atomic 
boolean so future loads/checks skipped. 





> LogLevel servlet to determine log impl before using setLevel
> ------------------------------------------------------------
>
>                 Key: HADOOP-18653
>                 URL: https://issues.apache.org/jira/browse/HADOOP-18653
>             Project: Hadoop Common
>          Issue Type: Sub-task
>            Reporter: Viraj Jasani
>            Assignee: Viraj Jasani
>            Priority: Major
>              Labels: pull-request-available
>
> LogLevel GET API is used to set log level for a given class name dynamically. 
> While we have cleaned up the commons-logging references, it would be great to 
> determine whether slf4j log4j adapter is in the classpath before allowing 
> client to set the log level.
> Proposed changes:
>  * Use slf4j logger factory to get the log reference for the given class name
>  * Use generic utility to identify if the slf4j log4j adapter is in the 
> classpath before using log4j API to update the log level
>  * If the log4j adapter is not in the classpath, report error in the output



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

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

Reply via email to