use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class Log4j1ConfigurationFactoryTest method testNullAppender.
@Test
public void testNullAppender() throws Exception {
final Configuration configuration = getConfiguration("config-1.2/log4j-NullAppender.properties");
final Appender appender = configuration.getAppender("NullAppender");
assertNotNull(appender);
assertEquals("NullAppender", appender.getName());
assertTrue(appender.getClass().getName(), appender instanceof NullAppender);
}
use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class LoggerTest method testReconfiguration.
@Test
public void testReconfiguration() throws Exception {
final Configuration oldConfig = context.getConfiguration();
final int MONITOR_INTERVAL_SECONDS = 5;
final File file = new File("target/test-classes/" + CONFIG);
final long orig = file.lastModified();
final long newTime = orig + 10000;
assertTrue("setLastModified should have succeeded.", file.setLastModified(newTime));
TimeUnit.SECONDS.sleep(MONITOR_INTERVAL_SECONDS + 1);
for (int i = 0; i < 17; ++i) {
logger.debug("Reconfigure");
}
Thread.sleep(100);
for (int i = 0; i < 20; i++) {
if (context.getConfiguration() != oldConfig) {
break;
}
Thread.sleep(50);
}
final Configuration newConfig = context.getConfiguration();
assertNotNull("No configuration", newConfig);
assertNotSame("Reconfiguration failed", newConfig, oldConfig);
}
use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class CustomLevelsWithFiltersTest method testConfiguration.
@Test
public void testConfiguration() {
final Configuration configuration = context.getConfiguration();
assertNotNull(configuration);
final FileAppender appender = configuration.getAppender("info");
assertNotNull(appender);
final CompositeFilter compFilter = (CompositeFilter) appender.getFilter();
assertNotNull(compFilter);
final Filter[] filters = compFilter.getFiltersArray();
assertNotNull(filters);
boolean foundLevel = false;
for (final Filter filter : filters) {
final ThresholdFilter tFilter = (ThresholdFilter) filter;
if (infom1Level.equals(tFilter.getLevel())) {
foundLevel = true;
break;
}
}
Assert.assertTrue("Level not found: " + infom1Level, foundLevel);
}
use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class LoggerUpdateTest method resetLevel.
@Test
public void resetLevel() {
final org.apache.logging.log4j.Logger logger = context.getLogger("com.apache.test");
logger.traceEntry();
List<LogEvent> events = app.getEvents();
assertEquals("Incorrect number of events. Expected 1, actual " + events.size(), 1, events.size());
app.clear();
final LoggerContext ctx = LoggerContext.getContext(false);
final Configuration config = ctx.getConfiguration();
final LoggerConfig loggerConfig = config.getLoggerConfig(LogManager.ROOT_LOGGER_NAME);
/* You could also specify the actual logger name as below and it will return the LoggerConfig used by the Logger.
LoggerConfig loggerConfig = getLoggerConfig("com.apache.test");
*/
loggerConfig.setLevel(Level.DEBUG);
// This causes all Loggers to refetch information from their LoggerConfig.
ctx.updateLoggers();
logger.traceEntry();
events = app.getEvents();
assertEquals("Incorrect number of events. Expected 0, actual " + events.size(), 0, events.size());
}
use of org.apache.logging.log4j.core.config.Configuration in project logging-log4j2 by apache.
the class PropertiesFileConfigTest method testReconfiguration.
@Test
public void testReconfiguration() throws Exception {
final Configuration oldConfig = context.getConfiguration();
final int MONITOR_INTERVAL_SECONDS = 5;
final File file = new File(CONFIG);
final long orig = file.lastModified();
final long newTime = orig + 10000;
assertTrue("setLastModified should have succeeded.", file.setLastModified(newTime));
TimeUnit.SECONDS.sleep(MONITOR_INTERVAL_SECONDS + 1);
for (int i = 0; i < 17; ++i) {
logger.debug("Reconfigure");
}
final int loopCount = 0;
Configuration newConfig;
do {
Thread.sleep(100);
newConfig = context.getConfiguration();
} while (newConfig == oldConfig && loopCount < 5);
assertNotSame("Reconfiguration failed", newConfig, oldConfig);
}
Aggregations