Search in sources :

Example 16 with Node

use of org.apache.logging.log4j.plugins.Node in project logging-log4j2 by apache.

the class RequiredValidatorTest method setUp.

@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() throws Exception {
    final PluginManager manager = new PluginManager("Test");
    manager.collectPlugins();
    plugin = (PluginType<ValidatingPlugin>) manager.getPluginType("Validator");
    assertNotNull(plugin, "Rebuild this module to make sure annotation processing kicks in.");
    node = new Node(null, "Validator", plugin);
}
Also used : PluginManager(org.apache.logging.log4j.plugins.util.PluginManager) ValidatingPlugin(org.apache.logging.log4j.plugins.test.validation.ValidatingPlugin) Node(org.apache.logging.log4j.plugins.Node) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 17 with Node

use of org.apache.logging.log4j.plugins.Node in project logging-log4j2 by apache.

the class ValidatingPluginWithGenericBuilderTest method setUp.

@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() throws Exception {
    final PluginManager manager = new PluginManager("Test");
    manager.collectPlugins();
    plugin = (PluginType<ValidatingPluginWithGenericBuilder>) manager.getPluginType("ValidatingPluginWithGenericBuilder");
    assertNotNull(plugin, "Rebuild this module to make sure annotation processing kicks in.");
    node = new Node(null, "Validator", plugin);
}
Also used : PluginManager(org.apache.logging.log4j.plugins.util.PluginManager) Node(org.apache.logging.log4j.plugins.Node) ValidatingPluginWithGenericBuilder(org.apache.logging.log4j.plugins.test.validation.ValidatingPluginWithGenericBuilder) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 18 with Node

use of org.apache.logging.log4j.plugins.Node in project logging-log4j2 by apache.

the class ValidatingPluginWithTypedBuilderTest method setUp.

@SuppressWarnings("unchecked")
@BeforeEach
public void setUp() throws Exception {
    final PluginManager manager = new PluginManager("Test");
    manager.collectPlugins();
    plugin = (PluginType<ValidatingPluginWithTypedBuilder>) manager.getPluginType("ValidatingPluginWithTypedBuilder");
    assertNotNull(plugin, "Rebuild this module to make sure annotation processing kicks in.");
    node = new Node(null, "Validator", plugin);
}
Also used : PluginManager(org.apache.logging.log4j.plugins.util.PluginManager) ValidatingPluginWithTypedBuilder(org.apache.logging.log4j.plugins.test.validation.ValidatingPluginWithTypedBuilder) Node(org.apache.logging.log4j.plugins.Node) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 19 with Node

use of org.apache.logging.log4j.plugins.Node in project logging-log4j2 by apache.

the class AppenderSet method createAppender.

public Appender createAppender(final String actualAppenderName, final String sourceAppenderName) {
    final Node node = nodeMap.get(actualAppenderName);
    if (node == null) {
        LOGGER.error("No node named {} in {}", actualAppenderName, this);
        return null;
    }
    node.getAttributes().put("name", sourceAppenderName);
    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 {} " + actualAppenderName);
    return null;
}
Also used : Appender(org.apache.logging.log4j.core.Appender) Node(org.apache.logging.log4j.plugins.Node) PluginNode(org.apache.logging.log4j.plugins.PluginNode)

Example 20 with Node

use of org.apache.logging.log4j.plugins.Node in project logging-log4j2 by apache.

the class AbstractConfiguration method processSelect.

/**
 * Handle Select nodes. This finds the first child condition that returns true and attaches its children
 * to the parent of the Select Node. Other Nodes are discarded.
 * @param selectNode The Select Node.
 * @param type The PluginType of the Select Node.
 * @return The list of Nodes to be added to the parent.
 */
protected List<Node> processSelect(final Node selectNode, final PluginType<?> type) {
    final List<Node> addList = new ArrayList<>();
    final SelectArbiter select = (SelectArbiter) createPluginObject(type, selectNode, null);
    final List<Arbiter> conditions = new ArrayList<>();
    for (final Node child : selectNode.getChildren()) {
        final PluginType<?> nodeType = child.getType();
        if (nodeType != null) {
            if (Arbiter.class.isAssignableFrom(nodeType.getPluginClass())) {
                final Arbiter condition = (Arbiter) createPluginObject(nodeType, child, null);
                conditions.add(condition);
                child.setObject(condition);
            } else {
                LOGGER.error("Invalid Node {} for Select. Must be a Condition", child.getName());
            }
        } else {
            LOGGER.error("No PluginType for node {}", child.getName());
        }
    }
    final Arbiter condition = select.evaluateConditions(conditions);
    if (condition != null) {
        for (final Node child : selectNode.getChildren()) {
            if (condition == child.getObject()) {
                addList.addAll(child.getChildren());
                processConditionals(child);
            }
        }
    }
    return addList;
}
Also used : SelectArbiter(org.apache.logging.log4j.core.config.arbiters.SelectArbiter) Node(org.apache.logging.log4j.plugins.Node) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) Arbiter(org.apache.logging.log4j.core.config.arbiters.Arbiter) SelectArbiter(org.apache.logging.log4j.core.config.arbiters.SelectArbiter)

Aggregations

Node (org.apache.logging.log4j.plugins.Node)27 PluginManager (org.apache.logging.log4j.plugins.util.PluginManager)7 BeforeEach (org.junit.jupiter.api.BeforeEach)7 ArrayList (java.util.ArrayList)6 Map (java.util.Map)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)4 Appender (org.apache.logging.log4j.core.Appender)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 IOException (java.io.IOException)2 LinkedHashMap (java.util.LinkedHashMap)2 Arbiter (org.apache.logging.log4j.core.config.arbiters.Arbiter)2 SelectArbiter (org.apache.logging.log4j.core.config.arbiters.SelectArbiter)2 HostAndPort (org.apache.logging.log4j.plugins.test.validation.HostAndPort)2 HashMap (java.util.HashMap)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 ConcurrentMap (java.util.concurrent.ConcurrentMap)1 Filter (org.apache.logging.log4j.core.Filter)1 AbstractAppender (org.apache.logging.log4j.core.appender.AbstractAppender)1 AsyncAppender (org.apache.logging.log4j.core.appender.AsyncAppender)1