@Override public Object visit(final Configuration configuration, final Node node, final LogEvent event, final StringBuilder log) { if (this.conversionType.isInstance(node)) { log.append("Node=").append(node.getName()); return node; } LOGGER.warn("Variable annotated with @PluginNode is not compatible with the type {}.", node.getClass()); return null; } }
private void verifyNodeChildrenUsed() { final List<Node> children = node.getChildren(); if (!(pluginType.isDeferChildren() || children.isEmpty())) { for (final Node child : children) { final String nodeType = node.getType().getElementName(); final String start = nodeType.equals(node.getName()) ? node.getName() : nodeType + ' ' + node.getName(); LOGGER.error("{} has no parameter that matches element {}", start, child.getName()); } } } }
@Override public String toString() { final StringBuilder sb = new StringBuilder("Route("); sb.append("type="); if (appenderRef != null) { sb.append("static Reference=").append(appenderRef); } else if (node != null) { sb.append("dynamic - type=").append(node.getName()); } else { sb.append("invalid Route"); } if (key != null) { sb.append(" key='").append(key).append('\''); } else { sb.append(" default"); } sb.append(')'); return sb.toString(); }
private static Map<String, ?> createPluginMap(final Node node) { final Map<String, Object> map = new LinkedHashMap<>(); for (final Node child : node.getChildren()) { final Object object = child.getObject(); map.put(child.getName(), object); } return map; }
private void printNodes(final String indent, final Node node, final StringBuilder sb) { sb.append(indent).append(node.getName()).append(" type: ").append(node.getType()).append("\n"); sb.append(indent).append(node.getAttributes().toString()).append("\n"); for (final Node child : node.getChildren()) { printNodes(indent + " ", child, sb); } } }
private void checkForRemainingAttributes() { final Map<String, String> attrs = node.getAttributes(); if (!attrs.isEmpty()) { final StringBuilder sb = new StringBuilder(); for (final String key : attrs.keySet()) { if (sb.length() == 0) { sb.append(node.getName()); sb.append(" contains "); if (attrs.size() == 1) { sb.append("an invalid element or attribute "); } else { sb.append("invalid attributes "); } } else { sb.append(", "); } StringBuilders.appendDqValue(sb, key); } LOGGER.error(sb.toString()); } }
protected void preConfigure(final Node node) { try { for (final Node child : node.getChildren()) { if (child.getType() == null) { LOGGER.error("Unable to locate plugin type for " + child.getName()); continue; } final Class<?> clazz = child.getType().getPluginClass(); if (clazz.isAnnotationPresent(Scheduled.class)) { configurationScheduler.incrementScheduledItems(); } preConfigure(child); } } catch (final Exception ex) { LOGGER.error("Error capturing node data for node " + node.getName(), ex); } }
private void setupAdvertisement() { if (advertiserNode != null) { final String nodeName = advertiserNode.getName(); final PluginType<?> type = pluginManager.getPluginType(nodeName); if (type != null) { final Class<? extends Advertiser> clazz = type.getPluginClass().asSubclass(Advertiser.class); try { advertiser = clazz.newInstance(); advertisement = advertiser.advertise(advertiserNode.getAttributes()); } catch (final InstantiationException e) { LOGGER.error("InstantiationException attempting to instantiate advertiser: {}", nodeName, e); } catch (final IllegalAccessException e) { LOGGER.error("IllegalAccessException attempting to instantiate advertiser: {}", nodeName, e); } } } }
LOGGER.error("Could not create plugin of type {} for element {}", this.clazz, node.getName(), e); return null; // no point in trying the factory method } catch (final Exception e) { LOGGER.error("Could not create plugin of type {} for element {}: {}", this.clazz, node.getName(), (e instanceof InvocationTargetException ? ((InvocationTargetException) e).getCause() : e).toString(), e); } catch (final Exception e) { LOGGER.error("Unable to invoke factory method in {} for element {}: {}", this.clazz, this.node.getName(), (e instanceof InvocationTargetException ? ((InvocationTargetException) e).getCause() : e).toString(), e); return null;
final Object childObject = child.getObject(); if (childObject == null) { LOGGER.error("Null object returned for {} in {}.", child.getName(), node.getName()); continue; return null; log.append(namedNode.getName()).append('(').append(namedNode.toString()).append(')'); node.getChildren().remove(namedNode); return namedNode.getObject();
LOGGER.debug(log.toString()); if (invalid) { throw new ConfigurationException("Arguments given for element " + node.getName() + " are invalid");
private void updateFilterNode(final Node target, final Node targetChildNode, final Node sourceChildNode, final PluginManager pluginManager) { if (CompositeFilter.class.isAssignableFrom(targetChildNode.getType().getPluginClass())) { final Node node = new Node(targetChildNode, sourceChildNode.getName(), sourceChildNode.getType()); node.getChildren().addAll(sourceChildNode.getChildren()); node.getAttributes().putAll(sourceChildNode.getAttributes()); targetChildNode.getChildren().add(node); } else { final PluginType pluginType = pluginManager.getPluginType(FILTERS); final Node filtersNode = new Node(targetChildNode, FILTERS, pluginType); final Node node = new Node(filtersNode, sourceChildNode.getName(), sourceChildNode.getType()); node.getAttributes().putAll(sourceChildNode.getAttributes()); final List<Node> children = filtersNode.getChildren(); children.add(targetChildNode); children.add(node); final List<Node> nodes = target.getChildren(); nodes.remove(targetChildNode); nodes.add(filtersNode); } }
LOGGER.debug(log.toString()); if (invalid) { throw new ConfigurationException("Arguments given for element " + node.getName() + " are invalid");
protected void doConfigure() { preConfigure(rootNode); configurationScheduler.start(); if (rootNode.hasChildren() && rootNode.getChildren().get(0).getName().equalsIgnoreCase("Properties")) { final Node first = rootNode.getChildren().get(0); createConfiguration(first, null); boolean setRoot = false; for (final Node child : rootNode.getChildren()) { if (child.getName().equalsIgnoreCase("Properties")) { if (tempLookup == subst.getVariableResolver()) { LOGGER.error("Properties declaration must be the first element in the configuration"); if (child.getName().equalsIgnoreCase("Scripts")) { for (final AbstractScript script : child.getObject(AbstractScript[].class)) { if (script instanceof ScriptRef) { } else if (child.getName().equalsIgnoreCase("Appenders")) { appenders = child.getObject(); } else if (child.isInstanceOf(Filter.class)) { addFilter(child.getObject(Filter.class)); } else if (child.getName().equalsIgnoreCase("Loggers")) { final Loggers l = child.getObject(); loggerConfigs = l.getMap(); } else if (child.getName().equalsIgnoreCase("CustomLevels")) { customLevels = child.getObject(CustomLevels.class).getCustomLevels(); } else if (child.isInstanceOf(CustomLevelConfig.class)) { "\"Scripts\"", "\"CustomLevels\"");
public Appender createAppender(final String appenderName, final String actualName) { final Node node = nodeMap.get(appenderName); if (node == null) { LOGGER.error("No node named {} in {}", appenderName, this); return null; } node.getAttributes().put("name", actualName); if (node.getType().getElementName().equals(Appender.ELEMENT_TYPE)) { final Node appNode = new Node(node); configuration.createConfiguration(appNode, null); if (appNode.getObject() instanceof Appender) { final Appender app = appNode.getObject(); app.start(); return app; } LOGGER.error("Unable to create Appender of type " + node.getName()); return null; } LOGGER.error("No Appender was configured for name {} " + appenderName); return null; } }
@Override public Object visit(final Configuration configuration, final Node node, final LogEvent event, final StringBuilder log) { final String name = this.annotation.value(); final String elementValue = node.getValue(); final String attributeValue = node.getAttributes().get("value"); String rawValue = null; // if neither is specified, return null (LOG4J2-1313) if (Strings.isNotEmpty(elementValue)) { if (Strings.isNotEmpty(attributeValue)) { LOGGER.error("Configuration contains {} with both attribute value ({}) AND element" + " value ({}). Please specify only one value. Using the element value.", node.getName(), attributeValue, elementValue); } rawValue = elementValue; } else { rawValue = removeAttributeValue(node.getAttributes(), "value"); } final String value = this.substitutor.replace(event, rawValue); StringBuilders.appendKeyDqValue(log, name, value); return value; } }
if (!targetChildNode.getName().equalsIgnoreCase(sourceChildNode.getName())) { continue; switch (targetChildNode.getName().toLowerCase()) { case PROPERTIES: case SCRIPTS: final Map<String, Node> targetLoggers = new HashMap<>(); for (final Node node : targetChildNode.getChildren()) { targetLoggers.put(node.getName(), node); final Node loggerNode = new Node(targetChildNode, node.getName(), node.getType()); if (targetNode != null) { targetNode.getAttributes().putAll(node.getAttributes()); final Node childNode = new Node(loggerNode, sourceLoggerChild.getName(), sourceLoggerChild.getType()); targetNode.getChildren().add(childNode); final Node childNode = new Node(loggerNode, sourceLoggerChild.getName(), sourceLoggerChild.getType()); childNode.getAttributes().putAll(sourceLoggerChild.getAttributes()); childNode.getChildren().addAll(sourceLoggerChild.getChildren()); if (childNode.getName().equalsIgnoreCase("AppenderRef")) { for (final Node targetChild : targetNode.getChildren()) { if (isSameReference(targetChild, childNode)) { if (sourceChildNode.getName().equalsIgnoreCase("Properties")) { target.getChildren().add(0, sourceChildNode);
@Override public void createConfiguration(final Node node, final LogEvent event) { final PluginType<?> type = node.getType(); if (type != null && type.isDeferChildren()) { node.setObject(createPluginObject(type, node, event)); } else { for (final Node child : node.getChildren()) { createConfiguration(child, event); } if (type == null) { if (node.getParent() != null) { LOGGER.error("Unable to locate plugin for {}", node.getName()); } } else { node.setObject(createPluginObject(type, node, event)); } } }
private Appender createAppender(final Route route, final LogEvent event) { final Node routeNode = route.getNode(); for (final Node node : routeNode.getChildren()) { if (node.getType().getElementName().equals(Appender.ELEMENT_TYPE)) { final Node appNode = new Node(node); configuration.createConfiguration(appNode, event); if (appNode.getObject() instanceof Appender) { final Appender app = appNode.getObject(); app.start(); return app; } error("Unable to create Appender of type " + node.getName()); return null; } } error("No Appender was configured for route " + route.getKey()); return null; }