use of org.apache.log4j.spi.AppenderAttachable in project logging-log4j2 by apache.
the class XmlConfiguration method buildAppender.
private Appender buildAppender(String className, Element appenderElement) {
try {
Appender appender = LoaderUtil.newInstanceOf(className);
PropertySetter propSetter = new PropertySetter(appender);
appender.setName(subst(appenderElement.getAttribute(NAME_ATTR)));
forEachElement(appenderElement.getChildNodes(), (currentElement) -> {
// Parse appender parameters
switch(currentElement.getTagName()) {
case PARAM_TAG:
setParameter(currentElement, propSetter);
break;
case LAYOUT_TAG:
appender.setLayout(parseLayout(currentElement));
break;
case FILTER_TAG:
Filter filter = parseFilters(currentElement);
if (filter != null) {
LOGGER.debug("Adding filter of type [{}] to appender named [{}]", filter.getClass(), appender.getName());
appender.addFilter(filter);
}
break;
case ERROR_HANDLER_TAG:
parseErrorHandler(currentElement, appender);
break;
case APPENDER_REF_TAG:
String refName = subst(currentElement.getAttribute(REF_ATTR));
if (appender instanceof AppenderAttachable) {
AppenderAttachable aa = (AppenderAttachable) appender;
Appender child = findAppenderByReference(currentElement);
LOGGER.debug("Attaching appender named [{}] to appender named [{}].", refName, appender.getName());
aa.addAppender(child);
} else {
LOGGER.error("Requesting attachment of appender named [{}] to appender named [{}]" + "which does not implement org.apache.log4j.spi.AppenderAttachable.", refName, appender.getName());
}
break;
default:
try {
parseUnrecognizedElement(appender, currentElement, props);
} catch (Exception ex) {
throw new ConsumerException(ex);
}
}
});
propSetter.activate();
return appender;
} catch (ConsumerException ex) {
Throwable t = ex.getCause();
if (t instanceof InterruptedException || t instanceof InterruptedIOException) {
Thread.currentThread().interrupt();
}
LOGGER.error("Could not create an Appender. Reported error follows.", t);
} catch (Exception oops) {
if (oops instanceof InterruptedException || oops instanceof InterruptedIOException) {
Thread.currentThread().interrupt();
}
LOGGER.error("Could not create an Appender. Reported error follows.", oops);
}
return null;
}
use of org.apache.log4j.spi.AppenderAttachable in project fabric8 by jboss-fuse.
the class Log4jLogQuery method reconnectAppender.
@Override
public void reconnectAppender() {
ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();
AppenderAttachable appenderAttachable = null;
if (loggerFactory instanceof AppenderAttachable) {
appenderAttachable = (AppenderAttachable) loggerFactory;
}
if (appenderAttachable == null) {
appenderAttachable = LogManager.getRootLogger();
}
if (appenderAttachable != null) {
appender.setName("LogQuery");
appenderAttachable.addAppender(appender);
} else {
LOG.error("No ILoggerFactory found so cannot attach appender!");
}
}
Aggregations