use of org.apache.logging.log4j.core.config.AppenderControl in project ignite by apache.
the class Log4J2Logger method fileName.
/** {@inheritDoc} */
@Nullable
@Override
public String fileName() {
for (Logger log = impl; log != null; log = log.getParent()) {
for (Appender a : log.getAppenders().values()) {
if (a instanceof FileAppender)
return ((FileAppender) a).getFileName();
if (a instanceof RollingFileAppender)
return ((RollingFileAppender) a).getFileName();
if (a instanceof RoutingAppender) {
try {
RoutingAppender routing = (RoutingAppender) a;
Field appsFiled = routing.getClass().getDeclaredField("appenders");
appsFiled.setAccessible(true);
Map<String, AppenderControl> appenders = (Map<String, AppenderControl>) appsFiled.get(routing);
for (AppenderControl control : appenders.values()) {
Appender innerApp = control.getAppender();
if (innerApp instanceof FileAppender)
return normilize(((FileAppender) innerApp).getFileName());
if (innerApp instanceof RollingFileAppender)
return normilize(((RollingFileAppender) innerApp).getFileName());
}
} catch (IllegalAccessException | NoSuchFieldException e) {
error("Failed to get file name (was the implementation of log4j2 changed?).", e);
}
}
}
}
return null;
}
use of org.apache.logging.log4j.core.config.AppenderControl in project logging-log4j2 by apache.
the class RoutingAppender method stop.
@Override
public boolean stop(final long timeout, final TimeUnit timeUnit) {
setStopping();
super.stop(timeout, timeUnit, false);
final Map<String, Appender> map = configuration.getAppenders();
for (final Map.Entry<String, AppenderControl> entry : appenders.entrySet()) {
final Appender appender = entry.getValue().getAppender();
if (!map.containsKey(appender.getName())) {
if (appender instanceof LifeCycle2) {
((LifeCycle2) appender).stop(timeout, timeUnit);
} else {
appender.stop();
}
}
}
setStopped();
return true;
}
use of org.apache.logging.log4j.core.config.AppenderControl in project logging-log4j2 by apache.
the class RoutingAppender method getControl.
private synchronized AppenderControl getControl(final String key, final LogEvent event) {
AppenderControl control = appenders.get(key);
if (control != null) {
return control;
}
Route route = null;
for (final Route r : routes.getRoutes()) {
if (r.getAppenderRef() == null && key.equals(r.getKey())) {
route = r;
break;
}
}
if (route == null) {
route = defaultRoute;
control = appenders.get(DEFAULT_KEY);
if (control != null) {
return control;
}
}
if (route != null) {
final Appender app = createAppender(route, event);
if (app == null) {
return null;
}
control = new AppenderControl(app, null, null);
appenders.put(key, control);
}
return control;
}
use of org.apache.logging.log4j.core.config.AppenderControl in project logging-log4j2 by apache.
the class AsyncAppender method start.
@Override
public void start() {
final Map<String, Appender> map = config.getAppenders();
final List<AppenderControl> appenders = new ArrayList<>();
for (final AppenderRef appenderRef : appenderRefs) {
final Appender appender = map.get(appenderRef.getRef());
if (appender != null) {
appenders.add(new AppenderControl(appender, appenderRef.getLevel(), appenderRef.getFilter()));
} else {
LOGGER.error("No appender named {} was configured", appenderRef);
}
}
if (errorRef != null) {
final Appender appender = map.get(errorRef);
if (appender != null) {
errorAppender = new AppenderControl(appender, null, null);
} else {
LOGGER.error("Unable to set up error Appender. No appender named {} was configured", errorRef);
}
}
if (appenders.size() > 0) {
thread = new AsyncThread(appenders, queue);
thread.setName("AsyncAppender-" + getName());
} else if (errorRef == null) {
throw new ConfigurationException("No appenders are available for AsyncAppender " + getName());
}
asyncQueueFullPolicy = AsyncQueueFullPolicyFactory.create();
thread.start();
super.start();
}
use of org.apache.logging.log4j.core.config.AppenderControl in project logging-log4j2 by apache.
the class FailoverAppender method failover.
private void failover(final LogEvent event, final Exception ex) {
final RuntimeException re = ex != null ? (ex instanceof LoggingException ? (LoggingException) ex : new LoggingException(ex)) : null;
boolean written = false;
Exception failoverException = null;
for (final AppenderControl control : failoverAppenders) {
try {
control.callAppender(event);
written = true;
break;
} catch (final Exception fex) {
if (failoverException == null) {
failoverException = fex;
}
}
}
if (!written && !ignoreExceptions()) {
if (re != null) {
throw re;
}
throw new LoggingException("Unable to write to failover appenders", failoverException);
}
}
Aggregations