Search in sources :

Example 26 with Node

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

the class CompositeConfiguration method setup.

@Override
public void setup() {
    final AbstractConfiguration targetConfiguration = configurations.get(0);
    staffChildConfiguration(targetConfiguration);
    final WatchManager watchManager = getWatchManager();
    final WatchManager targetWatchManager = targetConfiguration.getWatchManager();
    if (targetWatchManager.getIntervalSeconds() > 0) {
        watchManager.setIntervalSeconds(targetWatchManager.getIntervalSeconds());
        final Map<Source, Watcher> watchers = targetWatchManager.getConfigurationWatchers();
        for (final Map.Entry<Source, Watcher> entry : watchers.entrySet()) {
            watchManager.watch(entry.getKey(), entry.getValue().newWatcher(this, listeners, entry.getValue().getLastModified()));
        }
    }
    for (final AbstractConfiguration sourceConfiguration : configurations.subList(1, configurations.size())) {
        staffChildConfiguration(sourceConfiguration);
        final Node sourceRoot = sourceConfiguration.getRootNode();
        mergeStrategy.mergeConfigurations(rootNode, sourceRoot, getPluginManager());
        if (LOGGER.isEnabled(Level.ALL)) {
            final StringBuilder sb = new StringBuilder();
            printNodes("", rootNode, sb);
            System.out.println(sb.toString());
        }
        final int monitorInterval = sourceConfiguration.getWatchManager().getIntervalSeconds();
        if (monitorInterval > 0) {
            final int currentInterval = watchManager.getIntervalSeconds();
            if (currentInterval <= 0 || monitorInterval < currentInterval) {
                watchManager.setIntervalSeconds(monitorInterval);
            }
            final WatchManager sourceWatchManager = sourceConfiguration.getWatchManager();
            final Map<Source, Watcher> watchers = sourceWatchManager.getConfigurationWatchers();
            for (final Map.Entry<Source, Watcher> entry : watchers.entrySet()) {
                watchManager.watch(entry.getKey(), entry.getValue().newWatcher(this, listeners, entry.getValue().getLastModified()));
            }
        }
    }
}
Also used : AbstractConfiguration(org.apache.logging.log4j.core.config.AbstractConfiguration) Node(org.apache.logging.log4j.plugins.Node) Watcher(org.apache.logging.log4j.core.util.Watcher) Map(java.util.Map) WatchManager(org.apache.logging.log4j.core.util.WatchManager) Source(org.apache.logging.log4j.core.util.Source) ConfigurationSource(org.apache.logging.log4j.core.config.ConfigurationSource)

Example 27 with Node

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

the class CompositeConfiguration method printNodes.

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);
    }
}
Also used : Node(org.apache.logging.log4j.plugins.Node)

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