JAVA-14450: fix log4j2 MapAppender, and JSONLayout integration tests (#12681)

This commit is contained in:
Ehsan 2022-09-02 16:21:27 +02:00 committed by GitHub
parent 885d0d9e9e
commit 83282c54d1
3 changed files with 7 additions and 3 deletions

View File

@ -7,6 +7,8 @@ public class Log4j2ConsoleAndFile {
private static final Logger logger = LogManager.getLogger(Log4j2ConsoleAndFile.class);
// To enable the console and file appender, just rename the log4j2 file, under /src/main/resources, to log4j2.properties
// Reason: Having the log4j2.properties file overrides the log4j2.xml file, so that other appender classes would not work
public static void main(String[] args) {
logger.info("Hello World!");
logger.debug("Hello World!");

View File

@ -23,13 +23,15 @@ public class MapAppenderIntegrationTest {
@Test
public void whenLoggerEmitsLoggingEvent_thenAppenderReceivesEvent() throws Exception {
logger.error("Error log message from {}", this.getClass()
.getSimpleName());
LoggerContext context = LoggerContext.getContext(false);
Configuration config = context.getConfiguration();
MapAppender appender = config.getAppender("MapAppender");
int eventSizeBeforeLog = appender.getEventMap()
.size();
logger.error("Error log message from {}", this.getClass()
.getSimpleName());
assertEquals(appender.getEventMap()
.size(), 1);
.size(), ++eventSizeBeforeLog);
}
}