diff --git a/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/consoleandfile/Log4j2ConsoleAndFile.java b/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/consoleandfile/Log4j2ConsoleAndFile.java index 56119efd9e..598322cdc6 100644 --- a/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/consoleandfile/Log4j2ConsoleAndFile.java +++ b/logging-modules/log4j2/src/main/java/com/baeldung/logging/log4j2/consoleandfile/Log4j2ConsoleAndFile.java @@ -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!"); diff --git a/logging-modules/log4j2/src/main/resources/log4j2.properties b/logging-modules/log4j2/src/main/resources/log4j2 similarity index 100% rename from logging-modules/log4j2/src/main/resources/log4j2.properties rename to logging-modules/log4j2/src/main/resources/log4j2 diff --git a/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/appender/MapAppenderIntegrationTest.java b/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/appender/MapAppenderIntegrationTest.java index e340ebb784..21ec85ec80 100644 --- a/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/appender/MapAppenderIntegrationTest.java +++ b/logging-modules/log4j2/src/test/java/com/baeldung/logging/log4j2/appender/MapAppenderIntegrationTest.java @@ -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); } }