Search in sources :

Example 1 with ConfiguratonFileWatcher

use of org.apache.logging.log4j.core.config.ConfiguratonFileWatcher in project mule by mulesoft.

the class LoggerContextConfigurerTestCase method configurationMonitor.

@Test
public void configurationMonitor() throws Exception {
    WatchManager watchManager = mock(WatchManager.class);
    when(configuration.getWatchManager()).thenReturn(watchManager);
    when(context.getConfigFile()).thenReturn(new File(CURRENT_DIRECTORY).toURI());
    contextConfigurer.configure(context);
    ArgumentCaptor<ConfiguratonFileWatcher> captor = ArgumentCaptor.forClass(ConfiguratonFileWatcher.class);
    verify(watchManager).watchFile(any(File.class), captor.capture());
    assertThat(captor.getValue(), instanceOf(ConfiguratonFileWatcher.class));
    verify(watchManager).setIntervalSeconds(eq((int) TimeUnit.MILLISECONDS.toSeconds(MONITOR_INTERVAL)));
}
Also used : File(java.io.File) ConfiguratonFileWatcher(org.apache.logging.log4j.core.config.ConfiguratonFileWatcher) WatchManager(org.apache.logging.log4j.core.util.WatchManager) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 2 with ConfiguratonFileWatcher

use of org.apache.logging.log4j.core.config.ConfiguratonFileWatcher in project mule by mulesoft.

the class LoggerContextConfigurer method configureMonitor.

private void configureMonitor(MuleLoggerContext context) {
    Configuration configuration = context.getConfiguration();
    File configFile = null;
    if (context.getConfigFile() != null) {
        configFile = new File(context.getConfigFile().getPath());
    } else if (!StringUtils.isEmpty(configuration.getName())) {
        configFile = new File(configuration.getName());
    }
    if (configFile != null && configuration instanceof Reconfigurable) {
        configuration.getWatchManager().setIntervalSeconds(DEFAULT_MONITOR_INTERVAL_SECS);
        FileWatcher watcher = new ConfiguratonFileWatcher((Reconfigurable) configuration, getListeners(configuration));
        configuration.getWatchManager().watchFile(configFile, watcher);
    }
}
Also used : FileWatcher(org.apache.logging.log4j.core.util.FileWatcher) ConfiguratonFileWatcher(org.apache.logging.log4j.core.config.ConfiguratonFileWatcher) Configuration(org.apache.logging.log4j.core.config.Configuration) AbstractConfiguration(org.apache.logging.log4j.core.config.AbstractConfiguration) File(java.io.File) ConfiguratonFileWatcher(org.apache.logging.log4j.core.config.ConfiguratonFileWatcher) Reconfigurable(org.apache.logging.log4j.core.config.Reconfigurable)

Example 3 with ConfiguratonFileWatcher

use of org.apache.logging.log4j.core.config.ConfiguratonFileWatcher 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)3 ConfiguratonFileWatcher (org.apache.logging.log4j.core.config.ConfiguratonFileWatcher)3 Reconfigurable (org.apache.logging.log4j.core.config.Reconfigurable)2 FileWatcher (org.apache.logging.log4j.core.util.FileWatcher)2 AbstractConfiguration (org.apache.logging.log4j.core.config.AbstractConfiguration)1 Configuration (org.apache.logging.log4j.core.config.Configuration)1 ConfigurationSource (org.apache.logging.log4j.core.config.ConfigurationSource)1 WatchManager (org.apache.logging.log4j.core.util.WatchManager)1 Test (org.junit.Test)1 SmallTest (org.mule.tck.size.SmallTest)1