use of org.apache.logging.log4j.core.config.ConfigurationException in project logging-log4j2 by apache.
the class PropertiesConfigurationBuilder method createAppenderRef.
private AppenderRefComponentBuilder createAppenderRef(final String key, final Properties properties) {
final String ref = (String) properties.remove("ref");
if (Strings.isEmpty(ref)) {
throw new ConfigurationException("No ref attribute provided for AppenderRef " + key);
}
final AppenderRefComponentBuilder appenderRefBuilder = builder.newAppenderRef(ref);
final String level = (String) properties.remove("level");
if (!Strings.isEmpty(level)) {
appenderRefBuilder.addAttribute("level", level);
}
return addFiltersToComponent(appenderRefBuilder, properties);
}
use of org.apache.logging.log4j.core.config.ConfigurationException in project logging-log4j2 by apache.
the class PluginBuilder method generateParameters.
private Object[] generateParameters(final Method factory) {
final StringBuilder log = new StringBuilder();
final Class<?>[] types = factory.getParameterTypes();
final Annotation[][] annotations = factory.getParameterAnnotations();
final Object[] args = new Object[annotations.length];
boolean invalid = false;
for (int i = 0; i < annotations.length; i++) {
log.append(log.length() == 0 ? factory.getName() + "(" : ", ");
final String[] aliases = extractPluginAliases(annotations[i]);
for (final Annotation a : annotations[i]) {
if (a instanceof PluginAliases) {
// already processed
continue;
}
final PluginVisitor<? extends Annotation> visitor = PluginVisitors.findVisitor(a.annotationType());
if (visitor != null) {
final Object value = visitor.setAliases(aliases).setAnnotation(a).setConversionType(types[i]).setStrSubstitutor(configuration.getStrSubstitutor()).setMember(factory).visit(configuration, node, event, log);
// don't overwrite existing values if the visitor gives us no value to inject
if (value != null) {
args[i] = value;
}
}
}
final Collection<ConstraintValidator<?>> validators = ConstraintValidators.findValidators(annotations[i]);
final Object value = args[i];
final String argName = "arg[" + i + "](" + simpleName(value) + ")";
for (final ConstraintValidator<?> validator : validators) {
if (!validator.isValid(argName, value)) {
invalid = true;
}
}
}
log.append(log.length() == 0 ? factory.getName() + "()" : ")");
checkForRemainingAttributes();
verifyNodeChildrenUsed();
LOGGER.debug(log.toString());
if (invalid) {
throw new ConfigurationException("Arguments given for element " + node.getName() + " are invalid");
}
return args;
}
use of org.apache.logging.log4j.core.config.ConfigurationException 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.ConfigurationException in project logging-log4j2 by apache.
the class PluginBuilder method injectFields.
private void injectFields(final Builder<?> builder) throws IllegalAccessException {
final List<Field> fields = TypeUtil.getAllDeclaredFields(builder.getClass());
AccessibleObject.setAccessible(fields.toArray(new Field[] {}), true);
final StringBuilder log = new StringBuilder();
boolean invalid = false;
for (final Field field : fields) {
log.append(log.length() == 0 ? simpleName(builder) + "(" : ", ");
final Annotation[] annotations = field.getDeclaredAnnotations();
final String[] aliases = extractPluginAliases(annotations);
for (final Annotation a : annotations) {
if (a instanceof PluginAliases) {
// already processed
continue;
}
final PluginVisitor<? extends Annotation> visitor = PluginVisitors.findVisitor(a.annotationType());
if (visitor != null) {
final Object value = visitor.setAliases(aliases).setAnnotation(a).setConversionType(field.getType()).setStrSubstitutor(configuration.getStrSubstitutor()).setMember(field).visit(configuration, node, event, log);
// don't overwrite default values if the visitor gives us no value to inject
if (value != null) {
field.set(builder, value);
}
}
}
final Collection<ConstraintValidator<?>> validators = ConstraintValidators.findValidators(annotations);
final Object value = field.get(builder);
for (final ConstraintValidator<?> validator : validators) {
if (!validator.isValid(field.getName(), value)) {
invalid = true;
}
}
}
log.append(log.length() == 0 ? builder.getClass().getSimpleName() + "()" : ")");
LOGGER.debug(log.toString());
if (invalid) {
throw new ConfigurationException("Arguments given for element " + node.getName() + " are invalid");
}
checkForRemainingAttributes();
verifyNodeChildrenUsed();
}
use of org.apache.logging.log4j.core.config.ConfigurationException in project logging-log4j2 by apache.
the class PropertiesConfigurationBuilder method createRootLogger.
private RootLoggerComponentBuilder createRootLogger(final Properties properties) {
final String level = (String) properties.remove("level");
final String type = (String) properties.remove(CONFIG_TYPE);
final String location = (String) properties.remove("includeLocation");
final boolean includeLocation;
final RootLoggerComponentBuilder loggerBuilder;
if (type != null) {
if (type.equalsIgnoreCase("asyncRoot")) {
if (location != null) {
includeLocation = Boolean.parseBoolean(location);
loggerBuilder = builder.newAsyncRootLogger(level, includeLocation);
} else {
loggerBuilder = builder.newAsyncRootLogger(level);
}
} else {
throw new ConfigurationException("Unknown Logger type for root logger" + type);
}
} else {
if (location != null) {
includeLocation = Boolean.parseBoolean(location);
loggerBuilder = builder.newRootLogger(level, includeLocation);
} else {
loggerBuilder = builder.newRootLogger(level);
}
}
addLoggersToComponent(loggerBuilder, properties);
return addFiltersToComponent(loggerBuilder, properties);
}
Aggregations