org.apache.log4j.spi.Configurator Java Examples

The following examples show how to use org.apache.log4j.spi.Configurator. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XmlConfigurationFactory.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * Read the configuration file <code>configFilename</code> if it
 * exists. Moreover, a thread will be created that will periodically
 * check if <code>configFilename</code> has been created or
 * modified. The period is determined by the <code>delay</code>
 * argument. If a change or file creation is detected, then
 * <code>configFilename</code> is read to configure log4j.
 *
 * @param configFilename A log4j configuration file in XML format.
 * @param delay          The delay in milliseconds to wait between each check.
 */
public static void configureAndWatch(final String configFilename, final long delay) {
    try {
        File file = new File(configFilename);
        InputStream is = new FileInputStream(file);
        ConfigurationSource source = new ConfigurationSource(is, file);
        int seconds = (int) TimeUnit.MILLISECONDS.toSeconds(delay);
        XmlConfigurationFactory factory = new XmlConfigurationFactory(source, seconds);
        factory.doConfigure();
        org.apache.logging.log4j.core.config.Configurator.reconfigure(factory.getConfiguration());

    } catch (IOException ioe) {
        LOGGER.error("Unable to process configuration file {} due to {}", configFilename, ioe.getMessage());
    }
}
 
Example #2
Source File: XmlConfigurationFactory.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
/**
 * A static version of doConfigure(URL).
 */
public static void configure(final URL url) throws FactoryConfigurationError {
    try {
        InputStream is = url.openStream();
        ConfigurationSource source = new ConfigurationSource(is, url);
        XmlConfigurationFactory factory = new XmlConfigurationFactory(source, 0);
        factory.doConfigure();
        org.apache.logging.log4j.core.config.Configurator.reconfigure(factory.getConfiguration());
    } catch (IOException ioe) {
        LOGGER.error("Unable to process configuration {} due to {}", url.toString(), ioe.getMessage());
    }
}