Static method to change the Log4j config globally. This fails
if you're not using Log4j for now.
@param xmlConfig The text of a Log4j config file.
@param voltroot The VoltDB root path
545083
public static void configure(String xmlConfig, File voltroot) {
        try {
            Class<?> loggerClz = Class.forName("org.voltcore.logging.VoltLog4jLogger");
            assert(loggerClz != null);
            Method configureMethod = loggerClz.getMethod("configure", String.class, File.class);
            configureMethod.invoke(null, xmlConfig, voltroot);
        } catch (Exception e) {}
    }
1053116
public void setLogDataDirectory(String logDataDirectory) {
    	LogState state = ivLog.setDataDirectory(logDataDirectory);
    	if (state != null) {
    		updateLogConfiguration(state);
    		state.copyTo(ivLog);
    	}
    }
1172690
public static synchronized void update(Map<String, Object> newConfig) {
        if (newConfig == null)
            throw new NullPointerException("Updated config must not be null");

        boolean traceWasDisabled = !TraceComponent.isAnyTracingEnabled();

        // Update the logging configuration
        LogProviderConfig config = loggingConfig.get().get();
        if (config != null) {
            config.update(newConfig);

            Object o = newConfig.get("suppressSensitiveTrace");

            if (o != null) {
                if (o instanceof String) {
                    suppressSensitiveTrace = Boolean.parseBoolean((String) o);
                } else if (o instanceof Boolean) {
                    suppressSensitiveTrace = (Boolean) o;
                }
                if (suppressSensitiveTrace == true && safeLevelsIndex == null) {
                    setupSafeLevelsIndex();
                }
            }

            TraceSpecification newTs = setTraceSpec(config.getTraceString());

            // For updates only, warn if there are strings that we don't know
            if (defaultUpdated && newTs != null)
                newTs.warnUnmatchedSpecs();

            // we've updated the defaults from server.xml (we can set this a million times.. 
            // first pass through is the key.. 
            defaultUpdated = true;

            // Propagate updates to the delegate
            getDelegate().update(config);
        }

        // issue warning if trace has been enabled and there's no instrumentation agent
        if (!instrumentationAvailable && traceWasDisabled && TraceComponent.isAnyTracingEnabled()) {
            Tr.warning(TraceSpecification.getTc(), "INSTRUMENTATION_SERVICE_UNAVAILABLE");
        }
    }
1217841
private static void updateSniffingLoggersLevel(Logger logger) {

		InputStream settingIS = FoundationLogger.class
				.getResourceAsStream("/sniffingLogger.xml");
		if (settingIS == null) {
			logger.debug("file sniffingLogger.xml not found in classpath");
		} else {
			try {
				SAXBuilder builder = new SAXBuilder();
				Document document = builder.build(settingIS);
				settingIS.close();
				Element rootElement = document.getRootElement();
				List<Element> sniffingloggers = rootElement
						.getChildren("sniffingLogger");
				for (Element sniffinglogger : sniffingloggers) {
					String loggerName = sniffinglogger.getAttributeValue("id");
					Logger.getLogger(loggerName).setLevel(Level.TRACE);
				}
			} catch (Exception e) {
				logger.error(
						"cannot load the sniffing logger configuration file. error is: "
								+ e, e);
				throw new IllegalArgumentException(
						"Problem parsing sniffingLogger.xml", e);
			}
		}

	}
1256574
public static void configure(Properties configuration) {

        boolean activate = "true".equalsIgnoreCase(configuration
                .getProperty(Constants.ANDROLOG_ACTIVE));
        if (activate) {
            activateLogging();
        }

        boolean activate4Report = "true".equalsIgnoreCase(configuration
                .getProperty(Constants.ANDROLOG_REPORT_ACTIVE));
        if (activate4Report) {
            activateReporting();
        }

        detectWTFMethods();

        if (configuration.containsKey(Constants.ANDROLOG_DEFAULT_LEVEL)) {
            String level = configuration.getProperty(Constants.ANDROLOG_DEFAULT_LEVEL);
            defaultLogLevel = LogHelper.getLevel(level, defaultLogLevel);
        }

        if (configuration.containsKey(Constants.ANDROLOG_REPORT_DEFAULT_LEVEL)) {
            String level = configuration
                    .getProperty(Constants.ANDROLOG_REPORT_DEFAULT_LEVEL);
            defaultReportLevel = LogHelper.getLevel(level, defaultReportLevel);
        }

        @SuppressWarnings("unchecked")
        Enumeration<String> names = (Enumeration<String>) configuration
                .propertyNames();
        while (names.hasMoreElements()) {
            String name = names.nextElement();
            if (!name.startsWith(Constants.ANDROLOG_PREFIX)) {
                String level = configuration.getProperty(name);
                int log = LogHelper.getLevel(level, defaultLogLevel);
                logLevels.put(name, log);
            }
        }

        if (useWTF) {
            // Check if androlog configuration does not override this.
            if (configuration.containsKey(Constants.ANDROLOG_DELEGATE_WTF)) {
                String v = configuration.getProperty(Constants.ANDROLOG_DELEGATE_WTF);
                // If androlog.delegate.wtf is set to true, we really call
                // Log.wtf which
                // may terminate the process.
                useWTF = "true".equals(v.toLowerCase());
                // In other cases, androlog does log a message in the Constants.ASSERT
                // level.
            }
        }

        // Do we need to store the log entries for Reports ?
        enableLogEntryCollection = false;
        if (context != null
                && configuration.containsKey(Constants.ANDROLOG_REPORT_REPORTERS)) {
            // We enable the collection only if we have reporters AND a valid
            // context
            String s = configuration.getProperty(Constants.ANDROLOG_REPORT_REPORTERS);
            String[] senders = s.split(",");
            for (String sender : senders) {
                String cn = sender.trim();
                Reporter reporter = InstanceFactory.newReporter(cn);
                if (reporter != null) {
                    reporter.configure(configuration);
                    reporters.add(reporter);
                }
            }

            // Configure the UncaughtExceptionHandler
            if (configuration.containsKey(Constants.ANDROLOG_REPORT_EXCEPTION_HANDLER)
                    && "false".equals(configuration.getProperty(Constants.ANDROLOG_REPORT_EXCEPTION_HANDLER))) {
                exceptionHandlerActivated = false;
            }

            if (configuration.containsKey(Constants.ANDROLOG_REPORT_EXCEPTION_HANDLER_PROPAGATION)
                    && "false".equals(configuration.getProperty(Constants.ANDROLOG_REPORT_EXCEPTION_HANDLER_PROPAGATION))) {
                exceptionHandlerPropagation = false;
            }

            // Define an default error handler, reporting the error.
            if (exceptionHandlerActivated) {
                originalHandler = Thread.getDefaultUncaughtExceptionHandler();
                Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
                    @Override
                    public void uncaughtException(Thread arg0, Throwable arg1) {
                        report("Uncaught Exception", arg1);
                        // If there is a original handler, propagate the exception.
                        if (exceptionHandlerPropagation  && originalHandler != null) {
                            originalHandler.uncaughtException(arg0, arg1);
                        }
                    }
                });
            }

            if (configuration.containsKey(Constants.ANDROLOG_REPORT_TRIGGER_LEVEL)) {
                String l = configuration.getProperty(Constants.ANDROLOG_REPORT_TRIGGER_LEVEL);
                reportTriggerLevel = LogHelper.getLevel(l, defaultReportLevel);
            } else {
                reportTriggerLevel = Constants.ASSERT;
            }
            
            if (configuration.containsKey(Constants.ANDROLOG_REPORT_FACTORY)) {
                s = configuration.getProperty(Constants.ANDROLOG_REPORT_FACTORY);
                reportFactory = InstanceFactory.newReportFactory(s);
            }
            
            if ("true".equalsIgnoreCase(configuration
                .getProperty(Constants.ANDROLOG_REPORT_ADD_TIMESTAMP))) {
                addTimestampToReportLogs = true;
            }
            
            enableLogEntryCollection = true;
        }

        if (enableLogEntryCollection) {
            if (configuration.containsKey(Constants.ANDROLOG_REPORT_LOG_ITEMS)) {
                String p = configuration.getProperty(Constants.ANDROLOG_REPORT_LOG_ITEMS);
                maxOfEntriesInReports = Integer.parseInt(p);
            } else {
                maxOfEntriesInReports = 25; // Default
            }
            entries = new ArrayList<String>(maxOfEntriesInReports);
        }

    }
1277619
public static synchronized void init(LogProviderConfig config) {
        if (config == null)
            throw new NullPointerException("LogProviderConfig must not be null");

        if (loggingConfig.get().compareAndSet(null, config)) {
            // Only initialize Tr once -- all subsequent changes go through update
            // The synchronization of this method is gratuitous (just makes us feel better), 
            // it is called while the system is single threaded at startup. 

            // config.getTrDelegate() must not return null -- it should either
            // return a dummy/disabled delegate, or throw an exception so that startup
            // does not proceed.
            final TrService tr = config.getTrDelegate();
            if (tr == null)
                throw new NullPointerException("LogProviderConfig must provide a TrService delegate");
            Callable<TrService> result = new Callable<TrService>() {
                @Override
                public TrService call() throws Exception {
                    return tr;
                }
            };
            delegate = StaticValue.mutateStaticValue(delegate, result);
            delegate.get().init(config);

            // Validate and propagate the initial trace specification 
            setTraceSpec(config.getTraceString());

            // Set class that we want the LogManager to instantiate when someone
            // calls getLogger: This logger interacts only with the Tr/FFDC API: 
            // it is not dependent on the implementation of the underlying delegate
            WsLogManager.setWsLogger(com.ibm.ws.logging.internal.WsLogger.class);
        }
    }
998594
public static synchronized void update(Map<String, Object> newConfig) {
        if (newConfig == null)
            throw new NullPointerException("Updated config must not be null");

        // Update the logging configuration
        LogProviderConfig config = loggingConfig.get();
        if (config != null) {
            config.update(newConfig);
            // Propagate updates to the delegate
            getDelegate().update(config);
        }
    }
527326
public void init(ServletConfig config) throws ServletException {
        /*
         * Never forget super.init()!
         */
        super.init(config);

        /*
         * Grab the servlet context.
         */
        this.servletContext = config.getServletContext();

        // Get verbosity hint.
        String value = config.getInitParameter("verbose");
        if (value != null) {
            this.verbose = Boolean.valueOf(value);
        }

        // get encoding
        value = config.getInitParameter("encoding");
        if (value != null) {
            this.encoding = value;
        }

        // And now the real init work...
        if (verbose) {
            log("Parsing init parameters...");
        }

        String regex = config.getInitParameter(INIT_PARAM_RESOURCE_NAME_REGEX);
        if (regex != null) {
            String replacement = config.getInitParameter("resource.name.replacement");
            if (replacement == null) {
                Exception npex = new NullPointerException("resource.name.replacement");
                String message = "Init-param 'resource.name.replacement' not specified!";
                log(message, npex);
                throw new ServletException(message, npex);
            } else if ("EMPTY_STRING".equals(replacement)) {//<param-value></param-value> is prohibited
                replacement = "";
            }
            int flags = 0; // TODO : Parse pattern compile flags (literal names).
            String flagsStr = config.getInitParameter(INIT_PARAM_RESOURCE_NAME_REGEX_FLAGS);
            if (flagsStr != null && flagsStr.length() > 0) {
              flags = Integer.decode(flagsStr.trim());//throws NumberFormatException
            }
            resourceNamePattern = Pattern.compile(regex, flags);
            this.resourceNameReplacement = replacement;
            String all = config.getInitParameter("resource.name.replace.all");
            if (all != null) {
                this.resourceNameReplaceAll = Boolean.valueOf(all.trim());
            }
        }

        value = config.getInitParameter("logGROOVY861");
        if (value != null) {
            this.logGROOVY861 = Boolean.valueOf(value);
            // nothing else to do here
        }

        /*
         * If verbose, log the parameter values.
         */
        if (verbose) {
            log("(Abstract) init done. Listing some parameter name/value pairs:");
            log("verbose = " + verbose); // this *is* verbose! ;)
            log("reflection = " + reflection);
            log("logGROOVY861 = " + logGROOVY861);
            log(INIT_PARAM_RESOURCE_NAME_REGEX + " = " + resourceNamePattern);//toString == pattern
            log("resource.name.replacement = " + resourceNameReplacement);
        }
    }
87068
public void setLoggingConfigurations(java.util.Collection<LoggingConfiguration> loggingConfigurations) {
        if (loggingConfigurations == null) {
            this.loggingConfigurations = null;
            return;
        }

        this.loggingConfigurations = new java.util.ArrayList<LoggingConfiguration>(loggingConfigurations);
    }
784809
public void init(ServletConfig servletConfig) throws ServletException
    {
        super.init(servletConfig);
        ServletTask.initServlet(this, BasicServlet.SERVLET_TYPE.XML);
        Enumeration<?> paramNames = this.getInitParameterNames();
        while (paramNames.hasMoreElements())
        {
            String strProperty = (String)paramNames.nextElement();
            String strValue = this.getInitParameter(strProperty);
            m_initProperties.put(strProperty, strValue);
        }
    }
375926
public static void main(String[] args) {
        //Thread.setDefaultUncaughtExceptionHandler(new VoltUncaughtExceptionHandler());
        Configuration config = new Configuration(args);
        try {
            if (!config.validate()) {
                System.exit(-1);
            } else {
                if (config.m_startAction == StartAction.GET) {
                    cli(config);
                } else {
                    initialize(config);
                    instance().run();
                }
            }
        }
        catch (OutOfMemoryError e) {
            String errmsg = "VoltDB Main thread: ran out of Java memory. This node will shut down.";
            VoltDB.crashLocalVoltDB(errmsg, false, e);
        }
    }
1168246
public static void reconfigure(InputStream config, LoggerContext context) {
        if (context == null) {
            throw new NullPointerException("LoggerContext must not be null");
        }
        LoggerContext lc = context;
        JoranConfigurator jc = new JoranConfigurator();
        jc.setContext(lc);
        StatusUtil statusUtil = new StatusUtil(lc);
        List<SaxEvent> eventList = jc.recallSafeConfiguration();

        URL mainURL = ConfigurationWatchListUtil.getMainWatchURL(lc);
        lc.reset();
        long threshold = System.currentTimeMillis();
        try {
            jc.doConfigure(config);
            if (statusUtil.hasXMLParsingErrors(threshold)) {
                fallbackConfiguration(lc, eventList, mainURL);
            }
        } catch (JoranException e) {
            fallbackConfiguration(lc, eventList, mainURL);
        }
    }
949646
@Override
	public void applyConfig(final ConfigSettings config)
	{

		Object o = config
				.getConfigParameter(ConfigurationKeys.LOGGING_PATH_DIFFTOOL);
		if (o != null) {
			this.diffToolField.setText((String) o);
		}
		else {
			this.diffToolField.setText("");
		}

		o = config
				.getConfigParameter(ConfigurationKeys.LOGGING_LOGLEVEL_DIFFTOOL);
		if (o != null) {
			this.diffToolLogLevelComboBox.setSelectedItem(o);
		}

	}
1272992
private void parseLoggerConfig(final Node node,
			final ConfigSettings config, final ConfigurationKeys logPath,
			final ConfigurationKeys logLevel)
	{

		String name, value;
		Level level;
		Node nnode;
		NodeList list = node.getChildNodes();

		int length = list.getLength();
		for (int i = 0; i < length; i++) {
			nnode = list.item(i);

			name = nnode.getNodeName().toUpperCase();
			if (name.equals(KEY_LOG_PATH)) {

				value = nnode.getChildNodes().item(0).getNodeValue();
				value = value.substring(1, value.length() - 1);
				config.setConfigParameter(logPath, value);

			}
			else if (name.equals(KEY_LOG_LEVEL)) {

				level = Level.valueOf(nnode.getChildNodes().item(0)
						.getNodeValue());
				config.setConfigParameter(logLevel, level);
			}
		}
	}
760457
public void setRootLoggingLevel(final int loggingLevel) {
        rootLoggingLevel = loggingLevel;
        if (rootLoggerBack != null) {
            rootLoggerBack.setLevel(LoggingLevel.getLevelFromInt(loggingLevel));
        }
    }
1224451
public void xml(String xml) {
    if (LogLevel.DEBUG < logConfiguration.logLevel) {
      return;
    }
    printlnInternal(LogLevel.DEBUG, logConfiguration.xmlFormatter.format(xml));
  }
50379
@Override
    public void init(IBatchConfig batchConfig) throws BatchContainerServiceException {
        logger.entering(CLASSNAME, "init", batchConfig);
        this.batchConfig = batchConfig;
        logger.exiting(CLASSNAME, "init");
    }