use of org.apache.log4j.spi.ErrorHandler in project datanucleus-core by datanucleus.
the class PluginParserTest method testRequireBundleVersionLogged.
public void testRequireBundleVersionLogged() {
final java.util.Set messages = new HashSet();
Logger.getLogger("DataNucleus.General").addAppender(new Appender() {
public void setName(String arg0) {
}
public void setLayout(Layout arg0) {
}
public void setErrorHandler(ErrorHandler arg0) {
}
public boolean requiresLayout() {
return false;
}
public String getName() {
return "testappender123";
}
public Layout getLayout() {
return null;
}
public Filter getFilter() {
return null;
}
public ErrorHandler getErrorHandler() {
return null;
}
public void doAppend(LoggingEvent arg0) {
if (arg0.getLevel() != Level.DEBUG) {
messages.add(arg0.getRenderedMessage());
}
}
public void close() {
}
public void clearFilters() {
}
public void addFilter(Filter arg0) {
}
});
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION", true);
assertEquals(0, mgr.getExtensionPoints().length);
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST10.MF", null));
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST11.MF", null));
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST12.MF", null));
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST13.MF", null));
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST14.MF", null));
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST15.MF", null));
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST16.MF", null));
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST17.MF", null));
mgr.resolveConstraints();
try {
assertEquals(3, messages.size());
assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test12\" requires \"org.datanucleus.plugin.test11\" version \"(1.2.0.b2\" but the resolved bundle has version \"1.2.0.b2\" which is outside the expected range."));
assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test13\" requires \"org.datanucleus.plugin.test11\" version \"(1.2.0.c1\" but the resolved bundle has version \"1.2.0.b2\" which is outside the expected range."));
assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test15\" requires \"org.datanucleus.plugin.test11\" version \"(1.0.0.b2,1.2.0.b2)\" but the resolved bundle has version \"1.2.0.b2\" which is outside the expected range."));
} finally {
Logger.getLogger("DataNucleus.General").removeAppender("testappender123");
}
}
use of org.apache.log4j.spi.ErrorHandler in project logging-log4j2 by apache.
the class XmlConfiguration method parseErrorHandler.
/**
* Used internally to parse an {@link ErrorHandler} element.
*/
private void parseErrorHandler(Element element, Appender appender) {
ErrorHandler eh = (ErrorHandler) OptionConverter.instantiateByClassName(subst(element.getAttribute(CLASS_ATTR)), ErrorHandler.class, null);
if (eh != null) {
eh.setAppender(appender);
PropertySetter propSetter = new PropertySetter(eh);
forEachElement(element.getChildNodes(), (currentElement) -> {
String tagName = currentElement.getTagName();
if (tagName.equals(PARAM_TAG)) {
setParameter(currentElement, propSetter);
}
});
propSetter.activate();
appender.setErrorHandler(eh);
}
}
use of org.apache.log4j.spi.ErrorHandler in project logging-log4j2 by apache.
the class PropertiesConfiguration method buildAppender.
private Appender buildAppender(final String appenderName, final String className, final String prefix, final String layoutPrefix, final String filterPrefix, final Properties props) {
final Appender appender = newInstanceOf(className, "Appender");
if (appender == null) {
return null;
}
appender.setName(appenderName);
appender.setLayout(parseLayout(layoutPrefix, appenderName, props));
final String errorHandlerPrefix = prefix + ".errorhandler";
final String errorHandlerClass = OptionConverter.findAndSubst(errorHandlerPrefix, props);
if (errorHandlerClass != null) {
final ErrorHandler eh = parseErrorHandler(props, errorHandlerPrefix, errorHandlerClass, appender);
if (eh != null) {
appender.setErrorHandler(eh);
}
}
appender.addFilter(parseAppenderFilters(props, filterPrefix, appenderName));
final String[] keys = new String[] { layoutPrefix };
addProperties(appender, keys, props, prefix);
if (appender instanceof AppenderWrapper) {
addAppender(((AppenderWrapper) appender).getAppender());
} else {
addAppender(new AppenderAdapter(appender).getAdapter());
}
registry.put(appenderName, appender);
return appender;
}
use of org.apache.log4j.spi.ErrorHandler in project logging-log4j2 by apache.
the class PropertiesConfiguration method parseErrorHandler.
public ErrorHandler parseErrorHandler(final Properties props, final String errorHandlerPrefix, final String errorHandlerClass, final Appender appender) {
final ErrorHandler eh = newInstanceOf(errorHandlerClass, "ErrorHandler");
final String[] keys = new String[] { // @formatter:off
errorHandlerPrefix + "." + ROOT_REF, errorHandlerPrefix + "." + LOGGER_REF, errorHandlerPrefix + "." + APPENDER_REF_TAG };
// @formatter:on
addProperties(eh, keys, props, errorHandlerPrefix);
return eh;
}
use of org.apache.log4j.spi.ErrorHandler in project datanucleus-core by datanucleus.
the class PluginParserTest method testRequireBundleLogged.
public void testRequireBundleLogged() {
final java.util.Set messages = new HashSet();
Logger.getLogger("DataNucleus.General").addAppender(new Appender() {
public void setName(String arg0) {
}
public void setLayout(Layout arg0) {
}
public void setErrorHandler(ErrorHandler arg0) {
}
public boolean requiresLayout() {
return false;
}
public String getName() {
return "testappender123";
}
public Layout getLayout() {
return null;
}
public Filter getFilter() {
return null;
}
public ErrorHandler getErrorHandler() {
return null;
}
public void doAppend(LoggingEvent arg0) {
if (arg0.getRenderedMessage().indexOf("but it cannot be resolved") > 0) {
messages.add(arg0.getRenderedMessage());
}
}
public void close() {
}
public void clearFilters() {
}
public void addFilter(Filter arg0) {
}
});
ClassLoaderResolver clr = new ClassLoaderResolverImpl();
NonManagedPluginRegistry mgr = new NonManagedPluginRegistry(clr, "EXCEPTION", true);
assertEquals(0, mgr.getExtensionPoints().length);
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST3.MF", null));
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST4.MF", null));
mgr.registerBundle(clr.getResource("/org/datanucleus/samples/plugin/MANIFEST5.MF", null));
mgr.resolveConstraints();
try {
assertEquals(2, messages.size());
assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test5\" requires \"org.datanucleus.plugin.test6\" but it cannot be resolved."));
assertTrue(messages.contains("Bundle \"org.datanucleus.plugin.test5\" has an optional dependency to \"org.datanucleus.plugin.test7\" but it cannot be resolved"));
} finally {
Logger.getLogger("DataNucleus.General").removeAppender("testappender123");
}
}
Aggregations