當前位置: 首頁>>代碼示例>>Java>>正文


Java Configuration.stop方法代碼示例

本文整理匯總了Java中org.apache.logging.log4j.core.config.Configuration.stop方法的典型用法代碼示例。如果您正苦於以下問題:Java Configuration.stop方法的具體用法?Java Configuration.stop怎麽用?Java Configuration.stop使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.logging.log4j.core.config.Configuration的用法示例。


在下文中一共展示了Configuration.stop方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setConfiguration

import org.apache.logging.log4j.core.config.Configuration; //導入方法依賴的package包/類
/**
 * Set the Configuration to be used.
 * @param config The new Configuration.
 * @return The previous Configuration.
 */
private synchronized Configuration setConfiguration(final Configuration config) {
    if (config == null) {
        throw new NullPointerException("No Configuration was provided");
    }
    final Configuration prev = this.config;
    config.addListener(this);
    final Map<String, String> map = new HashMap<String, String>();
    map.put("hostName", NetUtils.getLocalHostname());
    map.put("contextName", name);
    config.addComponent(Configuration.CONTEXT_PROPERTIES, map);
    config.start();
    this.config = config;
    updateLoggers();
    if (prev != null) {
        prev.removeListener(this);
        prev.stop();
    }

    // notify listeners
    final PropertyChangeEvent evt = new PropertyChangeEvent(this, PROPERTY_CONFIG, prev, config);
    for (final PropertyChangeListener listener : propertyChangeListeners) {
        listener.propertyChange(evt);
    }
    return prev;
}
 
開發者ID:OuZhencong,項目名稱:log4j2,代碼行數:31,代碼來源:LoggerContext.java

示例2: testRollingFileAppender

import org.apache.logging.log4j.core.config.Configuration; //導入方法依賴的package包/類
private void testRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
	final Configuration configuration = getConfiguration(configResource);
	final Appender appender = configuration.getAppender(name);
	assertNotNull(appender);
	assertEquals(name, appender.getName());
	assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
	final RollingFileAppender rfa = (RollingFileAppender) appender;
	assertEquals("target/hadoop.log", rfa.getFileName());
	assertEquals(filePattern, rfa.getFilePattern());
	final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
	assertNotNull(triggeringPolicy);
	assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
	final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
	final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
	assertEquals(1, triggeringPolicies.length);
	final TriggeringPolicy tp = triggeringPolicies[0];
	assertTrue(tp.getClass().getName(), tp instanceof SizeBasedTriggeringPolicy);
	final SizeBasedTriggeringPolicy sbtp = (SizeBasedTriggeringPolicy) tp;
	assertEquals(256 * 1024 * 1024, sbtp.getMaxFileSize());
	final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
	assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
	final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
	assertEquals(20, drs.getMaxIndex());
	configuration.start();
	configuration.stop();
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:27,代碼來源:Log4j1ConfigurationFactoryTest.java

示例3: testDailyRollingFileAppender

import org.apache.logging.log4j.core.config.Configuration; //導入方法依賴的package包/類
private void testDailyRollingFileAppender(final String configResource, final String name, final String filePattern) throws URISyntaxException {
	final Configuration configuration = getConfiguration(configResource);
	final Appender appender = configuration.getAppender(name);
	assertNotNull(appender);
	assertEquals(name, appender.getName());
	assertTrue(appender.getClass().getName(), appender instanceof RollingFileAppender);
	final RollingFileAppender rfa = (RollingFileAppender) appender;
	assertEquals("target/hadoop.log", rfa.getFileName());
	assertEquals(filePattern, rfa.getFilePattern());
	final TriggeringPolicy triggeringPolicy = rfa.getTriggeringPolicy();
	assertNotNull(triggeringPolicy);
	assertTrue(triggeringPolicy.getClass().getName(), triggeringPolicy instanceof CompositeTriggeringPolicy);
	final CompositeTriggeringPolicy ctp = (CompositeTriggeringPolicy) triggeringPolicy;
	final TriggeringPolicy[] triggeringPolicies = ctp.getTriggeringPolicies();
	assertEquals(1, triggeringPolicies.length);
	final TriggeringPolicy tp = triggeringPolicies[0];
	assertTrue(tp.getClass().getName(), tp instanceof TimeBasedTriggeringPolicy);
	final TimeBasedTriggeringPolicy tbtp = (TimeBasedTriggeringPolicy) tp;
	assertEquals(1, tbtp.getInterval());
	final RolloverStrategy rolloverStrategy = rfa.getManager().getRolloverStrategy();
	assertTrue(rolloverStrategy.getClass().getName(), rolloverStrategy instanceof DefaultRolloverStrategy);
	final DefaultRolloverStrategy drs = (DefaultRolloverStrategy) rolloverStrategy;
	assertEquals(Integer.MAX_VALUE, drs.getMaxIndex());
	configuration.start();
	configuration.stop();
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:27,代碼來源:Log4j1ConfigurationFactoryTest.java

示例4: testConsole

import org.apache.logging.log4j.core.config.Configuration; //導入方法依賴的package包/類
private Layout<?> testConsole(final String configResource) throws Exception {
    final Configuration configuration = getConfiguration(configResource);
    final String name = "Console";
    final ConsoleAppender appender = configuration.getAppender(name);
    assertNotNull("Missing appender '" + name + "' in configuration " + configResource + " → " + configuration,
            appender);
    assertEquals(Target.SYSTEM_ERR, appender.getTarget());
    //
    final LoggerConfig loggerConfig = configuration.getLoggerConfig("com.example.foo");
    assertNotNull(loggerConfig);
    assertEquals(Level.DEBUG, loggerConfig.getLevel());
    configuration.start();
    configuration.stop();
    return appender.getLayout();
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:16,代碼來源:Log4j1ConfigurationFactoryTest.java

示例5: testFile

import org.apache.logging.log4j.core.config.Configuration; //導入方法依賴的package包/類
private Layout<?> testFile(final String configResource) throws Exception {
	final Configuration configuration = getConfiguration(configResource);
	final FileAppender appender = configuration.getAppender("File");
	assertNotNull(appender);
	assertEquals("target/mylog.txt", appender.getFileName());
	//
	final LoggerConfig loggerConfig = configuration.getLoggerConfig("com.example.foo");
	assertNotNull(loggerConfig);
	assertEquals(Level.DEBUG, loggerConfig.getLevel());
	configuration.start();
	configuration.stop();
	return appender.getLayout();
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:14,代碼來源:Log4j1ConfigurationFactoryTest.java

示例6: stop

import org.apache.logging.log4j.core.config.Configuration; //導入方法依賴的package包/類
/**
 * Blocks until all Log4j tasks have completed execution after a shutdown request and all appenders have shut down,
 * or the timeout occurs, or the current thread is interrupted, whichever happens first.
 * <p>
 * Not all appenders will honor this, it is a hint and not an absolute guarantee that the this method not block longer.
 * Setting timeout too low increase the risk of losing outstanding log events not yet written to the final
 * destination.
 * <p>
 * Log4j can start threads to perform certain actions like file rollovers, calling this method with a positive timeout will
 * block until the rollover thread is done.
 *
 * @param timeout the maximum time to wait, or 0 which mean that each apppender uses its default timeout, and don't wait for background
tasks
 * @param timeUnit
 *            the time unit of the timeout argument
 * @return {@code true} if the logger context terminated and {@code false} if the timeout elapsed before
 *         termination.
 * @since 2.7
 */
@Override
public boolean stop(final long timeout, final TimeUnit timeUnit) {
    LOGGER.debug("Stopping LoggerContext[name={}, {}]...", getName(), this);
    configLock.lock();
    try {
        if (this.isStopped()) {
            return true;
        }

        this.setStopping();
        try {
            Server.unregisterLoggerContext(getName()); // LOG4J2-406, LOG4J2-500
        } catch (final LinkageError | Exception e) {
            // LOG4J2-1506 Hello Android, GAE
            LOGGER.error("Unable to unregister MBeans", e);
        }
        if (shutdownCallback != null) {
            shutdownCallback.cancel();
            shutdownCallback = null;
        }
        final Configuration prev = configuration;
        configuration = NULL_CONFIGURATION;
        updateLoggers();
        if (prev instanceof LifeCycle2) {
            ((LifeCycle2) prev).stop(timeout, timeUnit);
        } else {
            prev.stop();
        }
        externalContext = null;
        LogManager.getFactory().removeContext(this);
    } finally {
        configLock.unlock();
        this.setStopped();
    }
    LOGGER.debug("Stopped LoggerContext[name={}, {}] with status {}", getName(), this, true);
    return true;
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:57,代碼來源:LoggerContext.java

示例7: setConfiguration

import org.apache.logging.log4j.core.config.Configuration; //導入方法依賴的package包/類
/**
 * Sets the Configuration to be used.
 *
 * @param config The new Configuration.
 * @return The previous Configuration.
 */
private Configuration setConfiguration(final Configuration config) {
    if (config == null) {
        LOGGER.error("No configuration found for context '{}'.", contextName);
        // No change, return the current configuration.
        return this.configuration;
    }
    configLock.lock();
    try {
        final Configuration prev = this.configuration;
        config.addListener(this);

        final ConcurrentMap<String, String> map = config.getComponent(Configuration.CONTEXT_PROPERTIES);

        try { // LOG4J2-719 network access may throw android.os.NetworkOnMainThreadException
            map.putIfAbsent("hostName", NetUtils.getLocalHostname());
        } catch (final Exception ex) {
            LOGGER.debug("Ignoring {}, setting hostName to 'unknown'", ex.toString());
            map.putIfAbsent("hostName", "unknown");
        }
        map.putIfAbsent("contextName", contextName);
        config.start();
        this.configuration = config;
        updateLoggers();
        if (prev != null) {
            prev.removeListener(this);
            prev.stop();
        }

        firePropertyChangeEvent(new PropertyChangeEvent(this, PROPERTY_CONFIG, prev, config));

        try {
            Server.reregisterMBeansAfterReconfigure();
        } catch (final LinkageError | Exception e) {
            // LOG4J2-716: Android has no java.lang.management
            LOGGER.error("Could not reconfigure JMX", e);
        }
        // AsyncLoggers update their nanoClock when the configuration changes
        Log4jLogEvent.setNanoClock(configuration.getNanoClock());

        return prev;
    } finally {
        configLock.unlock();
    }
}
 
開發者ID:apache,項目名稱:logging-log4j2,代碼行數:51,代碼來源:LoggerContext.java


注:本文中的org.apache.logging.log4j.core.config.Configuration.stop方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。