private static String initHiveLog4jCommon(Configuration conf, ConfVars confVarName) throws LogInitializationException { if (MetastoreConf.getVar(conf, confVarName).equals("")) { // if log4j configuration file not set, or could not found, use default setting return initHiveLog4jDefault(conf, "", confVarName); } else { // if log4j configuration file found successfully, use HiveConf property value String log4jFileName = MetastoreConf.getVar(conf, confVarName); File log4jConfigFile = new File(log4jFileName); boolean fileExists = log4jConfigFile.exists(); if (!fileExists) { // if property specified file not found in local file system // use default setting return initHiveLog4jDefault( conf, "Not able to find conf file: " + log4jConfigFile, confVarName); } else { // property speficied file found in local file system // use the specified file final boolean async = checkAndSetAsyncLogging(conf); // required for MDC based routing appender so that child threads can inherit the MDC context System.setProperty(DefaultThreadContextMap.INHERITABLE_MAP, "true"); Configurator.initialize(null, log4jFileName); logConfigLocation(); return "Logging initialized using configuration in " + log4jConfigFile + " Async: " + async; } } }
/** * Initialize log4j. * * @return an message suitable for display to the user * @throws LogInitializationException if log4j fails to initialize correctly */ public static String initHiveLog4j(Configuration conf) throws LogInitializationException { return initHiveLog4jCommon(conf, MetastoreConf.ConfVars.LOG4J_FILE); }
private static String initHiveLog4jDefault(Configuration conf, String logMessage, ConfVars confVarName) throws LogInitializationException { URL hive_l4j = null; switch (confVarName) { case LOG4J_FILE: hive_l4j = LogUtils.class.getClassLoader().getResource(HIVE_L4J); break; default: break; } if (hive_l4j != null) { final boolean async = checkAndSetAsyncLogging(conf); System.setProperty(DefaultThreadContextMap.INHERITABLE_MAP, "true"); Configurator.initialize(null, hive_l4j.toString()); logConfigLocation(); return (logMessage + "\n" + "Logging initialized using configuration in " + hive_l4j + " Async: " + async); } else { throw new LogInitializationException( logMessage + "Unable to initialize logging using " + LogUtils.HIVE_L4J + ", not found on CLASSPATH!"); } }
LogUtils.initHiveLog4j(conf); } else {
private static String initHiveLog4jDefault(Configuration conf, String logMessage, ConfVars confVarName) throws LogInitializationException { URL hive_l4j = null; switch (confVarName) { case LOG4J_FILE: hive_l4j = LogUtils.class.getClassLoader().getResource(HIVE_L4J); break; default: break; } if (hive_l4j != null) { final boolean async = checkAndSetAsyncLogging(conf); System.setProperty(DefaultThreadContextMap.INHERITABLE_MAP, "true"); Configurator.initialize(null, hive_l4j.toString()); logConfigLocation(); return (logMessage + "\n" + "Logging initialized using configuration in " + hive_l4j + " Async: " + async); } else { throw new LogInitializationException( logMessage + "Unable to initialize logging using " + LogUtils.HIVE_L4J + ", not found on CLASSPATH!"); } }
LogUtils.initHiveLog4j(conf); } else {
private static String initHiveLog4jCommon(Configuration conf, ConfVars confVarName) throws LogInitializationException { if (MetastoreConf.getVar(conf, confVarName).equals("")) { // if log4j configuration file not set, or could not found, use default setting return initHiveLog4jDefault(conf, "", confVarName); } else { // if log4j configuration file found successfully, use HiveConf property value String log4jFileName = MetastoreConf.getVar(conf, confVarName); File log4jConfigFile = new File(log4jFileName); boolean fileExists = log4jConfigFile.exists(); if (!fileExists) { // if property specified file not found in local file system // use default setting return initHiveLog4jDefault( conf, "Not able to find conf file: " + log4jConfigFile, confVarName); } else { // property speficied file found in local file system // use the specified file final boolean async = checkAndSetAsyncLogging(conf); // required for MDC based routing appender so that child threads can inherit the MDC context System.setProperty(DefaultThreadContextMap.INHERITABLE_MAP, "true"); Configurator.initialize(null, log4jFileName); logConfigLocation(); return "Logging initialized using configuration in " + log4jConfigFile + " Async: " + async; } } }
/** * Initialize log4j. * * @return an message suitable for display to the user * @throws LogInitializationException if log4j fails to initialize correctly */ public static String initHiveLog4j(Configuration conf) throws LogInitializationException { return initHiveLog4jCommon(conf, MetastoreConf.ConfVars.LOG4J_FILE); }