本文整理汇总了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;
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
}