static { // By default we use a DefaultRepositorySelector which always returns 'h'. Hierarchyh=newHierarchy(newRootLogger((Level) Level.DEBUG)); repositorySelector = newDefaultRepositorySelector(h); /** Search for the properties file log4j.properties in the CLASSPATH. */ Stringoverride= OptionConverter.getSystemProperty(DEFAULT_INIT_OVERRIDE_KEY, null);
// if there is no default init override, then get the resource // specified by the user or the default config file. if (override == null || "false".equalsIgnoreCase(override)) {
StringconfigurationOptionStr= OptionConverter.getSystemProperty(DEFAULT_CONFIGURATION_KEY, null); StringconfiguratorClassName= OptionConverter.getSystemProperty(CONFIGURATOR_CLASS_KEY, null); URLurl=null; // if the user has not specified the log4j.configuration // property, we search first for the file "log4j.xml" and then // "log4j.properties" if (configurationOptionStr == null) { url = Loader.getResource(DEFAULT_XML_CONFIGURATION_FILE); if (url == null) { url = Loader.getResource(DEFAULT_CONFIGURATION_FILE); } } else { try { url = newURL(configurationOptionStr); } catch (MalformedURLException ex) { // so, resource is not a URL: // attempt to get the resource from the class path url = Loader.getResource(configurationOptionStr); } } // If we have a non-null url, then delegate the rest of the // configuration to the OptionConverter.selectAndConfigure // method. if (url != null) { LogLog.debug("Using URL [" + url + "] for automatic log4j configuration."); try { OptionConverter.selectAndConfigure(url, configuratorClassName, LogManager.getLoggerRepository()); } catch (NoClassDefFoundError e) { LogLog.warn("Error during default initialization", e); } } else { LogLog.debug("Could not find resource: [" + configurationOptionStr + "]."); } } else { LogLog.debug("Default initialization of overridden by " + DEFAULT_INIT_OVERRIDE_KEY + "property."); } }