private void setupAppenderIfRequired(LogEvent event) { if (appenderControl.get() == null) { if (node.getType().getElementName().equalsIgnoreCase("appender")) { for (final Node cnode : node.getChildren()) { final Node appNode = new Node(cnode); config.createConfiguration(appNode, event);
Node defaultRouteNode = new Node(null, "test-route-default", defaultRouteType); defaultRouteNode.getChildren().add(nullAppenderChildNode); queryIdAppenderNode.getAttributes().put("name", "test-query-file-appender"); queryIdRouteNode.getChildren().add(queryIdAppenderNode); Node filterNode = new Node(queryIdAppenderNode, "test-filter", filterType); queryIdAppenderNode.getChildren().add(filterNode); layoutNode.getAttributes().put("pattern", LogDivertAppender.nonVerboseLayout); queryIdAppenderNode.getChildren().add(layoutNode);
PluginType<Route> defaultType = new PluginType<Route>(defaultEntry, Route.class, "Route"); Node nullNode = new Node(null, "Route", defaultType); nullNode.getChildren().add(nullChildNode); Route defaultRoute = Route.createRoute(null, "${ctx:queryId}", nullNode); childNode.getAttributes().put("name", "query-file-appender"); childNode.getAttributes().put("fileName", logLocation + "/${ctx:sessionId}/${ctx:queryId}"); node.getChildren().add(childNode); Node filterNode = new Node(childNode, "NameFilter", filterType); filterNode.getAttributes().put("loggingLevel", loggingMode.name()); childNode.getChildren().add(filterNode); Node layoutNode = new Node(childNode, "PatternLayout", layoutType); layoutNode.getAttributes().put("pattern", layout); childNode.getChildren().add(layoutNode);
private Node getLoggerNode(final Node parentNode, final String name) { for (final Node node : parentNode.getChildren()) { final String nodeName = node.getAttributes().get(NAME); if (name == null && nodeName == null) { return node; } if (nodeName != null && nodeName.equals(name)) { return node; } } return null; }
private static Collection<?> createPluginCollection(final Node node) { final List<Node> children = node.getChildren(); final Collection<Object> list = new ArrayList<>(children.size()); for (final Node child : children) { final Object object = child.getObject(); list.add(object); } return list; }
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; }
@Override public void setup() { final Iterator<Map.Entry<String, JsonNode>> iter = root.fields(); final List<Node> children = rootNode.getChildren(); while (iter.hasNext()) { final Map.Entry<String, JsonNode> entry = iter.next(); final JsonNode n = entry.getValue(); if (n.isObject()) { LOGGER.debug("Processing node for object {}", entry.getKey()); children.add(constructNode(entry.getKey(), rootNode, n)); } else if (n.isArray()) { LOGGER.error("Arrays are not supported at the root configuration."); } } LOGGER.debug("Completed parsing configuration"); if (status.size() > 0) { for (final Status s : status) { LOGGER.error("Error processing element {}: {}", s.name, s.errorType); } } }
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); } } }
public Node(final Node node) { this.parent = node.parent; this.name = node.name; this.type = node.type; this.attributes.putAll(node.getAttributes()); this.value = node.getValue(); for (final Node child : node.getChildren()) { this.children.add(new Node(child)); } this.object = node.object; }
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); } }
log.append("={"); boolean first = true; for (final Node child : node.getChildren()) { final PluginType<?> childType = child.getType(); if (name.equalsIgnoreCase(childType.getElementName()) || return null; node.getChildren().removeAll(used); final Node namedNode = findNamedNode(name, node.getChildren()); if (namedNode == null) { log.append(name).append("=null"); node.getChildren().remove(namedNode); return namedNode.getObject();
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 void setup() { final List<Node> children = rootNode.getChildren(); if (propertiesComponent.getComponents().size() > 0) { children.add(convertToNode(rootNode, propertiesComponent)); } if (scriptsComponent.getComponents().size() > 0) { children.add(convertToNode(rootNode, scriptsComponent)); } if (customLevelsComponent.getComponents().size() > 0) { children.add(convertToNode(rootNode, customLevelsComponent)); } children.add(convertToNode(rootNode, loggersComponent)); children.add(convertToNode(rootNode, appendersComponent)); if (filtersComponent.getComponents().size() > 0) { if (filtersComponent.getComponents().size() == 1) { children.add(convertToNode(rootNode, filtersComponent.getComponents().get(0))); } else { children.add(convertToNode(rootNode, filtersComponent)); } } rootComponent = null; }
@Override public AppenderSet build() { if (configuration == null) { LOGGER.error("Configuration is missing from AppenderSet {}", this); return null; } if (node == null) { LOGGER.error("No node in AppenderSet {}", this); return null; } final List<Node> children = node.getChildren(); if (children == null) { LOGGER.error("No children node in AppenderSet {}", this); return null; } final Map<String, Node> map = new HashMap<>(children.size()); for (final Node childNode : children) { final String key = childNode.getAttributes().get("name"); if (key == null) { LOGGER.error("The attribute 'name' is missing from from the node {} in AppenderSet {}", childNode, children); } else { map.put(key, childNode); } } return new AppenderSet(configuration, map); }
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); } }
final StringBuilder buffer = new StringBuilder(); final NodeList list = element.getChildNodes(); final List<Node> children = node.getChildren(); for (int i = 0; i < list.getLength(); i++) { final org.w3c.dom.Node w3cNode = list.item(i);
private void setupAppenderIfRequired(LogEvent event) { if (appenderControl.get() == null) { if (node.getType().getElementName().equalsIgnoreCase("appender")) { for (final Node cnode : node.getChildren()) { final Node appNode = new Node(cnode); config.createConfiguration(appNode, event);
protected Node convertToNode(final Node parent, final Component component) { final String name = component.getPluginType(); final PluginType<?> pluginType = pluginManager.getPluginType(name); final Node node = new Node(parent, name, pluginType); node.getAttributes().putAll(component.getAttributes()); node.setValue(component.getValue()); final List<Node> children = node.getChildren(); for (final Component child : component.getComponents()) { children.add(convertToNode(node, child)); } return node; } }
@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; }