From d3312af5721e1f513e97f8f11989aaffceb2fd60 Mon Sep 17 00:00:00 2001 From: liuyunfei Date: Wed, 1 Mar 2017 21:44:05 +0800 Subject: [PATCH] MetaStore needs to reinitialize log4j to allow log specific settings via hiveconf take effect --- .../hadoop/hive/metastore/HiveMetaStore.java | 23 +++++++++++++------- 1 files changed, 15 insertions(+), 8 deletions(-) diff --git a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java index 07eca38..311be76 100644 --- a/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java +++ b/metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java @@ -129,6 +129,8 @@ import org.apache.hadoop.util.StringUtils; import org.apache.hive.common.util.HiveStringUtils; import org.apache.hive.common.util.ShutdownHookManager; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.LoggerContext; import org.apache.thrift.TException; import org.apache.thrift.TProcessor; import org.apache.thrift.protocol.TBinaryProtocol; @@ -6928,17 +6930,22 @@ public static void main(String[] args) throws Throwable { // any log specific settings via hiveconf will be ignored Properties hiveconf = cli.addHiveconfToSystemProperties(); - // If the log4j.configuration property hasn't already been explicitly set, - // use Hive's default log4j configuration - if (System.getProperty("log4j.configurationFile") == null) { - // NOTE: It is critical to do this here so that log4j is reinitialized - // before any of the other core hive classes are loaded - try { + // NOTE: It is critical to do this here so that log4j is reinitialized + // before any of the other core hive classes are loaded + try { + // If the log4j.configuration property hasn't already been explicitly set, + // use Hive's default log4j configuration + if (System.getProperty("log4j.configurationFile") == null) { LogUtils.initHiveLog4j(); - } catch (LogInitializationException e) { - HMSHandler.LOG.warn(e.getMessage()); + }else{ + //reconfigure log4j after settings via hiveconf are write into System Properties + LoggerContext context = (LoggerContext)LogManager.getContext(false); + context.reconfigure(); } + } catch (LogInitializationException e) { + HMSHandler.LOG.warn(e.getMessage()); } + HiveStringUtils.startupShutdownMessage(HiveMetaStore.class, args, LOG); try { -- 1.7.1