use of org.apache.logging.log4j.core.test.junit.LoggerContextSource in project logging-log4j2 by apache.
the class PropertiesConfigurationTest method testPropertiesConfiguration.
@Test
@LoggerContextSource("log4j2-properties.properties")
void testPropertiesConfiguration(final Configuration config) {
assertEquals(config.getState(), LifeCycle.State.STARTED, "Incorrect State: " + config.getState());
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertEquals(1, appenders.size(), "Incorrect number of Appenders: " + appenders.size());
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertEquals(2, loggers.size(), "Incorrect number of LoggerConfigs: " + loggers.size());
final Filter filter = config.getFilter();
assertNotNull(filter, "No Filter");
assertTrue(filter instanceof ThresholdFilter, "Not a Threshold Filter");
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
use of org.apache.logging.log4j.core.test.junit.LoggerContextSource in project logging-log4j2 by apache.
the class PropertiesConfigurationTest method testRollingFile.
@Test
@LoggerContextSource("log4j-rolling.properties")
void testRollingFile(final Configuration config) {
assertEquals(config.getState(), LifeCycle.State.STARTED, "Incorrect State: " + config.getState());
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertEquals(appenders.size(), 3, "Incorrect number of Appenders: " + appenders.size());
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertEquals(loggers.size(), 2, "Incorrect number of LoggerConfigs: " + loggers.size());
final Filter filter = config.getFilter();
assertNotNull(filter, "No Filter");
assertThat(filter, instanceOf(ThresholdFilter.class));
final Logger logger = LogManager.getLogger(getClass());
logger.info("Welcome to Log4j!");
}
use of org.apache.logging.log4j.core.test.junit.LoggerContextSource in project logging-log4j2 by apache.
the class PropertiesConfigurationTest method testTrailingSpaceOnLevel.
@Test
@LoggerContextSource("log4j2-properties-trailing-space-on-level.properties")
void testTrailingSpaceOnLevel(final Configuration config) {
assertEquals(config.getState(), LifeCycle.State.STARTED, "Incorrect State: " + config.getState());
final Map<String, Appender> appenders = config.getAppenders();
assertNotNull(appenders);
assertEquals(appenders.size(), 1, "Incorrect number of Appenders: " + appenders.size());
final Map<String, LoggerConfig> loggers = config.getLoggers();
assertNotNull(loggers);
assertEquals(loggers.size(), 2, "Incorrect number of LoggerConfigs: " + loggers.size());
final Filter filter = config.getFilter();
assertNotNull(filter, "No Filter");
assertThat(filter, instanceOf(ThresholdFilter.class));
final Logger logger = LogManager.getLogger(getClass());
assertEquals(Level.DEBUG, logger.getLevel(), "Incorrect level " + logger.getLevel());
logger.debug("Welcome to Log4j!");
}
use of org.apache.logging.log4j.core.test.junit.LoggerContextSource in project logging-log4j2 by apache.
the class CassandraAppenderIT method appendManyEvents.
@Disabled("Doesn't work in Java 11 at this Cassandra version")
@Test
@CassandraFixture(keyspace = "test", setup = DDL)
@LoggerContextSource("CassandraAppenderTest.xml")
public void appendManyEvents(final LoggerContext context, final Cluster cluster) throws Exception {
final Logger logger = context.getLogger(getClass());
ThreadContext.put("test", "mdc");
ThreadContext.push("ndc");
for (int i = 0; i < 20; i++) {
logger.info(MarkerManager.getMarker("MARKER"), "Test log message");
}
ThreadContext.clearAll();
TimeUnit.SECONDS.sleep(3);
int i = 0;
try (final Session session = cluster.connect("test")) {
for (final Row row : session.execute("SELECT * FROM logs")) {
assertNotNull(row.get("id", UUID.class));
assertNotNull(row.get("timeid", UUID.class));
assertNotNull(row.get("timestamp", Date.class));
assertEquals("Test log message", row.getString("message"));
assertEquals("MARKER", row.getString("marker"));
assertEquals("INFO", row.getString("level"));
assertEquals(getClass().getName(), row.getString("logger"));
final Map<String, String> mdc = row.getMap("mdc", String.class, String.class);
assertEquals(1, mdc.size());
assertEquals("mdc", mdc.get("test"));
final List<String> ndc = row.getList("ndc", String.class);
assertEquals(1, ndc.size());
assertEquals("ndc", ndc.get(0));
++i;
}
}
assertEquals(20, i);
}
use of org.apache.logging.log4j.core.test.junit.LoggerContextSource in project logging-log4j2 by apache.
the class ConfigurationFactoryTest method xinclude.
@Test
@LoggerContextSource("log4j-xinclude.xml")
void xinclude(final LoggerContext context) throws IOException {
checkConfiguration(context);
final Path logFile = Paths.get("target", "test-xinclude.log");
checkFileLogger(context, logFile);
}
Aggregations