You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kyuubi.apache.org by ch...@apache.org on 2023/08/03 11:27:40 UTC

[kyuubi] branch master updated: [KYUUBI #5129] KyuubiBeeline should redirect JDK logging

This is an automated email from the ASF dual-hosted git repository.

chengpan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kyuubi.git


The following commit(s) were added to refs/heads/master by this push:
     new f41a8e5b3 [KYUUBI #5129] KyuubiBeeline should redirect JDK logging
f41a8e5b3 is described below

commit f41a8e5b3dc4b443c988a0867e4b315e8767c0e5
Author: Cheng Pan <ch...@apache.org>
AuthorDate: Thu Aug 3 19:27:31 2023 +0800

    [KYUUBI #5129] KyuubiBeeline should redirect JDK logging
    
    ### _Why are the changes needed?_
    
    Otherwise we can not see JDK logs like Krb5.
    
    ### _How was this patch tested?_
    - [ ] Add some test cases that check the changes thoroughly including negative and positive cases if possible
    
    - [ ] Add screenshots for manual tests if appropriate
    
    - [x] [Run test](https://kyuubi.readthedocs.io/en/master/contributing/code/testing.html#running-tests) locally before make a pull request
    
    Closes #5129 from pan3793/beeline-log.
    
    Closes #5129
    
    100094823 [Cheng Pan] KyuubiBeeline should redirect JDK logging
    
    Authored-by: Cheng Pan <ch...@apache.org>
    Signed-off-by: Cheng Pan <ch...@apache.org>
---
 kyuubi-hive-beeline/pom.xml                              |  5 +++++
 .../main/java/org/apache/hive/beeline/KyuubiBeeLine.java | 16 ++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/kyuubi-hive-beeline/pom.xml b/kyuubi-hive-beeline/pom.xml
index 7a841f082..ff14e7839 100644
--- a/kyuubi-hive-beeline/pom.xml
+++ b/kyuubi-hive-beeline/pom.xml
@@ -161,6 +161,11 @@
             <artifactId>log4j-slf4j-impl</artifactId>
         </dependency>
 
+        <dependency>
+            <groupId>org.slf4j</groupId>
+            <artifactId>jul-to-slf4j</artifactId>
+        </dependency>
+
         <dependency>
             <groupId>org.apache.logging.log4j</groupId>
             <artifactId>log4j-api</artifactId>
diff --git a/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiBeeLine.java b/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiBeeLine.java
index 50a0c133a..224cbb3ce 100644
--- a/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiBeeLine.java
+++ b/kyuubi-hive-beeline/src/main/java/org/apache/hive/beeline/KyuubiBeeLine.java
@@ -30,6 +30,22 @@ import org.apache.kyuubi.util.reflect.DynFields;
 import org.apache.kyuubi.util.reflect.DynMethods;
 
 public class KyuubiBeeLine extends BeeLine {
+
+  static {
+    try {
+      // We use reflection here to handle the case where users remove the
+      // slf4j-to-jul bridge order to route their logs to JUL.
+      Class<?> bridgeClass = Class.forName("org.slf4j.bridge.SLF4JBridgeHandler");
+      bridgeClass.getMethod("removeHandlersForRootLogger").invoke(null);
+      boolean installed = (boolean) bridgeClass.getMethod("isInstalled").invoke(null);
+      if (!installed) {
+        bridgeClass.getMethod("install").invoke(null);
+      }
+    } catch (ReflectiveOperationException cnf) {
+      // can't log anything yet so just fail silently
+    }
+  }
+
   public static final String KYUUBI_BEELINE_DEFAULT_JDBC_DRIVER =
       "org.apache.kyuubi.jdbc.KyuubiHiveDriver";
   protected KyuubiCommands commands = new KyuubiCommands(this);