use of org.apache.log4j.rewrite.RewritePolicy in project logging-log4j2 by apache.
the class XmlConfiguration method parseRewritePolicy.
public RewritePolicy parseRewritePolicy(Element rewritePolicyElement) {
String className = subst(rewritePolicyElement.getAttribute(CLASS_ATTR));
LOGGER.debug("Class name: [" + className + ']');
RewritePolicy policy = manager.parseRewritePolicy(className, rewritePolicyElement, this);
if (policy == null) {
policy = buildRewritePolicy(className, rewritePolicyElement);
}
return policy;
}
use of org.apache.log4j.rewrite.RewritePolicy in project logging-log4j2 by apache.
the class XmlConfiguration method buildRewritePolicy.
private RewritePolicy buildRewritePolicy(String className, Element element) {
try {
RewritePolicy policy = LoaderUtil.newInstanceOf(className);
PropertySetter propSetter = new PropertySetter(policy);
forEachElement(element.getChildNodes(), (currentElement) -> {
if (currentElement.getTagName().equalsIgnoreCase(PARAM_TAG)) {
setParameter(currentElement, propSetter);
}
});
propSetter.activate();
return policy;
} catch (ConsumerException ex) {
Throwable t = ex.getCause();
if (t instanceof InterruptedException || t instanceof InterruptedIOException) {
Thread.currentThread().interrupt();
}
LOGGER.error("Could not create an RewritePolicy. Reported error follows.", t);
} catch (Exception oops) {
if (oops instanceof InterruptedException || oops instanceof InterruptedIOException) {
Thread.currentThread().interrupt();
}
LOGGER.error("Could not create an RewritePolicy. Reported error follows.", oops);
}
return null;
}
use of org.apache.log4j.rewrite.RewritePolicy in project logging-log4j2 by apache.
the class RewriteAppenderBuilder method parseAppender.
@Override
public Appender parseAppender(final String name, final String appenderPrefix, final String layoutPrefix, final String filterPrefix, final Properties props, final PropertiesConfiguration configuration) {
String appenderRef = getProperty(APPENDER_REF_TAG);
Filter filter = configuration.parseAppenderFilters(props, filterPrefix, name);
String policyPrefix = appenderPrefix + ".rewritePolicy";
String className = getProperty(policyPrefix);
RewritePolicy policy = configuration.getBuilderManager().parseRewritePolicy(className, policyPrefix, props, configuration);
String level = getProperty(THRESHOLD_PARAM);
if (appenderRef == null) {
LOGGER.warn("No appender references configured for AsyncAppender {}", name);
return null;
}
Appender appender = configuration.parseAppender(props, appenderRef);
if (appender == null) {
LOGGER.warn("Cannot locate Appender {}", appenderRef);
return null;
}
return createAppender(name, level, new String[] { appenderRef }, policy, filter, configuration);
}
use of org.apache.log4j.rewrite.RewritePolicy in project logging-log4j2 by apache.
the class RewriteAppenderBuilder method parseAppender.
@Override
public Appender parseAppender(final Element appenderElement, final XmlConfiguration config) {
String name = getNameAttribute(appenderElement);
Holder<List<String>> appenderRefs = new Holder<>(new ArrayList<>());
Holder<RewritePolicy> rewritePolicyHolder = new Holder<>();
Holder<String> level = new Holder<>();
Holder<Filter> filter = new Holder<>();
forEachElement(appenderElement.getChildNodes(), (currentElement) -> {
switch(currentElement.getTagName()) {
case APPENDER_REF_TAG:
Appender appender = config.findAppenderByReference(currentElement);
if (appender != null) {
appenderRefs.get().add(appender.getName());
}
break;
case REWRITE_POLICY_TAG:
{
RewritePolicy policy = config.parseRewritePolicy(currentElement);
if (policy != null) {
rewritePolicyHolder.set(policy);
}
break;
}
case FILTER_TAG:
{
filter.set(config.parseFilters(currentElement));
break;
}
case PARAM_TAG:
{
if (getNameAttributeKey(currentElement).equalsIgnoreCase(THRESHOLD_PARAM)) {
String value = getValueAttribute(currentElement);
if (value == null) {
LOGGER.warn("No value supplied for Threshold parameter, ignoring.");
} else {
level.set(value);
}
}
break;
}
}
});
return createAppender(name, level.get(), appenderRefs.get().toArray(new String[0]), rewritePolicyHolder.get(), filter.get(), config);
}
Aggregations