diff --git a/README.md b/README.md index 0ed0957..63944ff 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ logCapture * [Cucumber stepdefs](#cucumber-stepdefs) * [Cucumber DTOs](#cucumber-dtos) * [Changes](#changes) + * [3.2.1](#321) * [3.2.0](#320) * [3.1.0](#310) * [3.0.0](#300) @@ -41,7 +42,7 @@ Add log-capture as a test dependency to your project. If you use Maven, add this de.dm.infrastructure log-capture - 3.2.0 + 3.2.1 test ``` @@ -283,6 +284,10 @@ public class LogEntry { ## Changes +### 3.2.1 + +Added deprecated `addAppenderAndSetLogLevelToDebug()` again for compatibility + ### 3.2.0 Added fluent API diff --git a/pom.xml b/pom.xml index e3f1f17..035d7cc 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ de.dm.infrastructure log-capture - 3.1.0-SNAPSHOT + 3.2.1-SNAPSHOT Log Capture Makes it possible to capture logs and assert if things have been logged diff --git a/src/main/java/de/dm/infrastructure/logcapture/LogCapture.java b/src/main/java/de/dm/infrastructure/logcapture/LogCapture.java index ca700bd..fcad31d 100644 --- a/src/main/java/de/dm/infrastructure/logcapture/LogCapture.java +++ b/src/main/java/de/dm/infrastructure/logcapture/LogCapture.java @@ -83,14 +83,22 @@ public void addAppenderAndSetLogLevelToTrace() { setLogLevelToTrace(); } + /** + * delegates to {@link LogCapture#addAppenderAndSetLogLevelToTrace()} for compatibility + */ + @Deprecated + public void addAppenderAndSetLogLevelToDebug() { + addAppenderAndSetLogLevelToTrace(); + } + private void setLogLevelToTrace() { if (originalLogLevels != null) { throw new IllegalStateException("LogCapture.addAppenderAndSetLogLevelToTrace() should not be called only once or after calling removeAppenderAndResetLogLevel() again."); } originalLogLevels = new HashMap<>(); capturedPackages.forEach(packageName -> { - Logger packageLogger = rootLogger.getLoggerContext().getLogger(packageName); - originalLogLevels.put(packageName, packageLogger.getLevel()); + Logger packageLogger = rootLogger.getLoggerContext().getLogger(packageName); + originalLogLevels.put(packageName, packageLogger.getLevel()); rootLogger.getLoggerContext().getLogger(packageName).setLevel(Level.TRACE); } ); diff --git a/src/test/java/de/dm/infrastructure/logcapture/LogCaptureTest.java b/src/test/java/de/dm/infrastructure/logcapture/LogCaptureTest.java index b5f34bf..4e7568b 100644 --- a/src/test/java/de/dm/infrastructure/logcapture/LogCaptureTest.java +++ b/src/test/java/de/dm/infrastructure/logcapture/LogCaptureTest.java @@ -186,4 +186,20 @@ private void logLevelIsResetTo(Level originalLevel) { assertThat(comExampleLogger.getLevel()).isEqualTo(originalLevel); } + + private void logLevelIsResetWithDeprecatedMedhod() { + final ch.qos.logback.classic.Logger rootLogger = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME); + final ch.qos.logback.classic.Logger comExampleLogger = rootLogger.getLoggerContext().getLogger("com.example"); + + comExampleLogger.setLevel(INFO); + + LogCapture logCapture = LogCapture.forPackages("com.example"); + logCapture.addAppenderAndSetLogLevelToDebug(); + + assertThat(comExampleLogger.getLevel()).isEqualTo(TRACE); + + logCapture.removeAppenderAndResetLogLevel(); + + assertThat(comExampleLogger.getLevel()).isEqualTo(INFO); + } } diff --git a/src/test/java/de/dm/infrastructure/logcapture/LogCaptureWrongUsageTest.java b/src/test/java/de/dm/infrastructure/logcapture/LogCaptureWrongUsageTest.java index 42faa69..79bc728 100644 --- a/src/test/java/de/dm/infrastructure/logcapture/LogCaptureWrongUsageTest.java +++ b/src/test/java/de/dm/infrastructure/logcapture/LogCaptureWrongUsageTest.java @@ -24,4 +24,11 @@ void resetWithoutInitializationFails() { void assertionWithoutInitializationFails() { assertThrows(IllegalStateException.class, () -> logCapture.assertLogged(INFO, "something")); } + + @Test + void deprecatedAddAppenderDelegates() { + logCapture.addAppenderAndSetLogLevelToDebug(); + + assertThrows(IllegalStateException.class, () -> logCapture.addAppenderAndSetLogLevelToDebug()); + } }