Search in sources :

Example 1 with FileWatcher

use of org.apache.logging.log4j.core.util.FileWatcher 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();
    final FileWatcher fileWatcher = new ConfiguratonFileWatcher(this, listeners);
    if (targetWatchManager.getIntervalSeconds() > 0) {
        watchManager.setIntervalSeconds(targetWatchManager.getIntervalSeconds());
        final Map<File, FileWatcher> watchers = targetWatchManager.getWatchers();
        for (final Map.Entry<File, FileWatcher> entry : watchers.entrySet()) {
            if (entry.getValue() instanceof ConfiguratonFileWatcher) {
                watchManager.watchFile(entry.getKey(), fileWatcher);
            }
        }
    }
    for (final AbstractConfiguration sourceConfiguration : configurations.subList(1, configurations.size())) {
        staffChildConfiguration(sourceConfiguration);
        final Node sourceRoot = sourceConfiguration.getRootNode();
        mergeStrategy.mergConfigurations(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<File, FileWatcher> watchers = sourceWatchManager.getWatchers();
            for (final Map.Entry<File, FileWatcher> entry : watchers.entrySet()) {
                if (entry.getValue() instanceof ConfiguratonFileWatcher) {
                    watchManager.watchFile(entry.getKey(), fileWatcher);
                }
            }
        }
    }
}
Also used : AbstractConfiguration(org.apache.logging.log4j.core.config.AbstractConfiguration) FileWatcher(org.apache.logging.log4j.core.util.FileWatcher) ConfiguratonFileWatcher(org.apache.logging.log4j.core.config.ConfiguratonFileWatcher) Node(org.apache.logging.log4j.core.config.Node) ConfiguratonFileWatcher(org.apache.logging.log4j.core.config.ConfiguratonFileWatcher) File(java.io.File) Map(java.util.Map) WatchManager(org.apache.logging.log4j.core.util.WatchManager)

Example 2 with FileWatcher

use of org.apache.logging.log4j.core.util.FileWatcher in project logging-log4j2 by apache.

the class BuiltConfiguration method setMonitorInterval.

public void setMonitorInterval(final int intervalSeconds) {
    if (this instanceof Reconfigurable && intervalSeconds > 0) {
        final ConfigurationSource configSource = getConfigurationSource();
        if (configSource != null) {
            final File configFile = configSource.getFile();
            if (intervalSeconds > 0) {
                getWatchManager().setIntervalSeconds(intervalSeconds);
                if (configFile != null) {
                    final FileWatcher watcher = new ConfiguratonFileWatcher((Reconfigurable) this, listeners);
                    getWatchManager().watchFile(configFile, watcher);
                }
            }
        }
    }
}
Also used : ConfigurationSource(org.apache.logging.log4j.core.config.ConfigurationSource) FileWatcher(org.apache.logging.log4j.core.util.FileWatcher) ConfiguratonFileWatcher(org.apache.logging.log4j.core.config.ConfiguratonFileWatcher) File(java.io.File) ConfiguratonFileWatcher(org.apache.logging.log4j.core.config.ConfiguratonFileWatcher) Reconfigurable(org.apache.logging.log4j.core.config.Reconfigurable)

Aggregations

File (java.io.File)2 ConfiguratonFileWatcher (org.apache.logging.log4j.core.config.ConfiguratonFileWatcher)2 FileWatcher (org.apache.logging.log4j.core.util.FileWatcher)2 Map (java.util.Map)1 AbstractConfiguration (org.apache.logging.log4j.core.config.AbstractConfiguration)1 ConfigurationSource (org.apache.logging.log4j.core.config.ConfigurationSource)1 Node (org.apache.logging.log4j.core.config.Node)1 Reconfigurable (org.apache.logging.log4j.core.config.Reconfigurable)1 WatchManager (org.apache.logging.log4j.core.util.WatchManager)1