use of org.apache.logging.log4j.core.async.AsyncLoggerConfig in project logging-log4j2 by apache.
the class AbstractConfiguration method stop.
/**
* Tear down the configuration.
*/
@Override
public boolean stop(final long timeout, final TimeUnit timeUnit) {
this.setStopping();
super.stop(timeout, timeUnit, false);
LOGGER.trace("Stopping {}...", this);
for (final LoggerConfig loggerConfig : loggerConfigs.values()) {
loggerConfig.getReliabilityStrategy().beforeStopConfiguration(this);
}
root.getReliabilityStrategy().beforeStopConfiguration(this);
final String cls = getClass().getSimpleName();
LOGGER.trace("{} notified {} ReliabilityStrategies that config will be stopped.", cls, loggerConfigs.size() + 1);
if (!loggerConfigs.isEmpty()) {
LOGGER.trace("{} stopping {} LoggerConfigs.", cls, loggerConfigs.size());
for (final LoggerConfig logger : loggerConfigs.values()) {
logger.stop(timeout, timeUnit);
}
}
LOGGER.trace("{} stopping root LoggerConfig.", cls);
if (!root.isStopped()) {
root.stop(timeout, timeUnit);
}
if (hasAsyncLoggers()) {
LOGGER.trace("{} stopping AsyncLoggerConfigDisruptor.", cls);
asyncLoggerConfigDisruptor.stop(timeout, timeUnit);
}
// Stop the appenders in reverse order in case they still have activity.
final Appender[] array = appenders.values().toArray(new Appender[appenders.size()]);
final List<Appender> async = getAsyncAppenders(array);
if (!async.isEmpty()) {
// LOG4J2-511, LOG4J2-392 stop AsyncAppenders first
LOGGER.trace("{} stopping {} AsyncAppenders.", cls, async.size());
for (final Appender appender : async) {
if (appender instanceof LifeCycle2) {
((LifeCycle2) appender).stop(timeout, timeUnit);
} else {
appender.stop();
}
}
}
LOGGER.trace("{} notifying ReliabilityStrategies that appenders will be stopped.", cls);
for (final LoggerConfig loggerConfig : loggerConfigs.values()) {
loggerConfig.getReliabilityStrategy().beforeStopAppenders();
}
root.getReliabilityStrategy().beforeStopAppenders();
LOGGER.trace("{} stopping remaining Appenders.", cls);
int appenderCount = 0;
for (int i = array.length - 1; i >= 0; --i) {
if (array[i].isStarted()) {
// then stop remaining Appenders
if (array[i] instanceof LifeCycle2) {
((LifeCycle2) array[i]).stop(timeout, timeUnit);
} else {
array[i].stop();
}
appenderCount++;
}
}
LOGGER.trace("{} stopped {} remaining Appenders.", cls, appenderCount);
LOGGER.trace("{} cleaning Appenders from {} LoggerConfigs.", cls, loggerConfigs.size() + 1);
for (final LoggerConfig loggerConfig : loggerConfigs.values()) {
// LOG4J2-520, LOG4J2-392:
// Important: do not clear appenders until after all AsyncLoggerConfigs
// have been stopped! Stopping the last AsyncLoggerConfig will
// shut down the disruptor and wait for all enqueued events to be processed.
// Only *after this* the appenders can be cleared or events will be lost.
loggerConfig.clearAppenders();
}
root.clearAppenders();
if (watchManager.isStarted()) {
watchManager.stop(timeout, timeUnit);
}
configurationScheduler.stop(timeout, timeUnit);
if (advertiser != null && advertisement != null) {
advertiser.unadvertise(advertisement);
}
setStopped();
LOGGER.debug("Stopped {} OK", this);
return true;
}
use of org.apache.logging.log4j.core.async.AsyncLoggerConfig in project logging-log4j2 by apache.
the class Server method registerLoggerConfigs.
private static void registerLoggerConfigs(final LoggerContext ctx, final MBeanServer mbs, final Executor executor) throws InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
final Map<String, LoggerConfig> map = ctx.getConfiguration().getLoggers();
for (final String name : map.keySet()) {
final LoggerConfig cfg = map.get(name);
final LoggerConfigAdmin mbean = new LoggerConfigAdmin(ctx, cfg);
register(mbs, mbean, mbean.getObjectName());
if (cfg instanceof AsyncLoggerConfig) {
final AsyncLoggerConfig async = (AsyncLoggerConfig) cfg;
final RingBufferAdmin rbmbean = async.createRingBufferAdmin(ctx.getName());
register(mbs, rbmbean, rbmbean.getObjectName());
}
}
}
Aggregations