From 3e63d768b00f82ee56bb907200c3e14169d88e85 Mon Sep 17 00:00:00 2001 From: Daniel Flassak Date: Mon, 28 Feb 2022 11:05:05 +0100 Subject: [PATCH 1/3] don't use the deprecated API in ReadableApiTest --- src/test/java/com/example/app/ReadableApiTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/example/app/ReadableApiTest.java b/src/test/java/com/example/app/ReadableApiTest.java index 2d2fa24..a9818a4 100644 --- a/src/test/java/com/example/app/ReadableApiTest.java +++ b/src/test/java/com/example/app/ReadableApiTest.java @@ -13,7 +13,6 @@ import static de.dm.infrastructure.logcapture.ExpectedLoggerName.logger; import static de.dm.infrastructure.logcapture.ExpectedMarker.marker; import static de.dm.infrastructure.logcapture.ExpectedMdcEntry.mdc; -import static de.dm.infrastructure.logcapture.ExpectedMdcEntry.withMdc; import static de.dm.infrastructure.logcapture.LogExpectation.any; import static de.dm.infrastructure.logcapture.LogExpectation.debug; import static de.dm.infrastructure.logcapture.LogExpectation.error; @@ -504,7 +503,7 @@ void customMdcMatcherSucceeds() { logCapture.assertLogged( info("hello", - withMdc("key", mdcValue -> mdcValue.equals("value")))); + mdc("key", mdcValue -> mdcValue.equals("value")))); } @Test From b7091fde1a32148b16147d5059acca3925040b67 Mon Sep 17 00:00:00 2001 From: Daniel Flassak Date: Mon, 28 Feb 2022 11:09:58 +0100 Subject: [PATCH 2/3] update README and improve javadoc --- README.md | 16 ++++++++++++++++ .../infrastructure/logcapture/LogCapture.java | 18 +++++++++--------- 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 960fda6..fb2b87f 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,10 @@ The default matchers can match level and/or message. But there are additional ma #### MDC content ```java +import static de.dm.infrastructure.logcapture.ExpectedMdcEntry.mdc; + +... + MDC.put("key", "value"); log.info("did something"); @@ -90,6 +94,10 @@ logCapture.info("did something", mdc("key", "value"));` #### Exceptions ```java +import static de.dm.infrastructure.logcapture.ExpectedException.exception; + +... + log.warn("oh no!", new IllegalArgumentException("shame on you!", new NullPointerException("never use null"))); @@ -109,6 +117,10 @@ logCapture.assertLogged( #### Markers ```java +import static de.dm.infrastructure.logcapture.ExpectedMarker.marker; + +... + log.info(MarkerFactory.getMarker("my-marker"), "hello with marker"); logCapture.info("hello with marker", marker("my-marker")); @@ -117,6 +129,10 @@ logCapture.info("hello with marker", marker("my-marker")); #### Logger name ```java +import static de.dm.infrastructure.logcapture.ExpectedLoggerName.logger; + +... + log.info("did something"); logCapture.info("did something", logger("com.acme.foo")); diff --git a/src/main/java/de/dm/infrastructure/logcapture/LogCapture.java b/src/main/java/de/dm/infrastructure/logcapture/LogCapture.java index 199f1ae..b1f2d6c 100644 --- a/src/main/java/de/dm/infrastructure/logcapture/LogCapture.java +++ b/src/main/java/de/dm/infrastructure/logcapture/LogCapture.java @@ -139,7 +139,7 @@ public void removeAppenderAndResetLogLevel() { * @return a LastCapturedLogEvent from which .thenLogged(...) can be called to assert if things have been logged in a specific order * * @throws AssertionError if the expected log message has not been logged - * @deprecated use the new assertion methods (withMdc(), withException(), assertLogged(), assertLoggedInOrder()) instead + * @deprecated use the new assertion methods from ({@link #assertLogged(LogExpectation)}) instead. Use {@link ExpectedMdcEntry#mdc(String, String)} for MDC assertions. */ @Deprecated public LastCapturedLogEvent assertLogged(Level level, String regex, ExpectedMdcEntry... expectedMdcEntries) { @@ -297,7 +297,7 @@ public class LastCapturedLogEvent { * @return another LastCapturedLogEvent - for obvious reasons * * @throws AssertionError if the expected log message has not been logged - * @deprecated use the new assertion methods (withMdc(), withException(), assertLogged(), assertLoggedInOrder()) instead + * @deprecated use the new assertion methods from ({@link #assertLoggedInOrder(LogExpectation...)} (LogExpectation)}) instead. Use {@link ExpectedMdcEntry#mdc(String, String)} for MDC assertions. */ @Deprecated public LastCapturedLogEvent thenLogged(Level level, String regex, ExpectedMdcEntry... expectedMdcEntries) { @@ -308,7 +308,7 @@ public LastCapturedLogEvent thenLogged(Level level, String regex, ExpectedMdcEnt * assert that nothing else has been logged except for the asserted log messages * * @throws AssertionError if something else has been logged - * @deprecated use the new assertion methods (withMdc(), withException(), assertLogged(), assertLoggedInOrder()) instead + * @deprecated use the new log assertions with {@link LogAsserter.NothingElseLoggedAsserter#assertNothingElseLogged()} instead */ @Deprecated public void assertNothingElseLogged() { @@ -334,7 +334,7 @@ public void assertNothingElseLogged() { * * @return FluentLogAssertion to assert the messages with MDC * - * @deprecated use the new assertion methods (withMdc(), withException(), assertLogged(), assertLoggedInOrder()) instead + * @deprecated use {@link #with(LogEventMatcher...)} before ({@link #assertLoggedInOrder(LogExpectation...)} or {@link #assertLoggedInAnyOrder(LogExpectation...)} instead */ @Deprecated public FluentLogAssertion withMdcForAll(String key, String regex) { @@ -353,7 +353,7 @@ public FluentLogAssertion withMdcForAll(String key, String regex) { * * @return FluentLogAssertion to assert an error message * - * @deprecated use the new assertion methods (withMdc(), withException(), assertLogged(), assertLoggedInOrder()) instead + * @deprecated use {@link LogExpectation#error(LogEventMatcher...)} instead */ @Deprecated public FluentLogAssertion.ConfiguredLogAssertion error() { @@ -372,7 +372,7 @@ public FluentLogAssertion.ConfiguredLogAssertion error() { * * @return FluentLogAssertion to assert an warn message * - * @deprecated use the new assertion methods (withMdc(), withException(), assertLogged(), assertLoggedInOrder()) instead + * @deprecated use {@link LogExpectation#warn(LogEventMatcher...)} instead */ @Deprecated public FluentLogAssertion.ConfiguredLogAssertion warn() { @@ -391,7 +391,7 @@ public FluentLogAssertion.ConfiguredLogAssertion warn() { * * @return FluentLogAssertion to assert an info message * - * @deprecated use the new assertion methods (withMdc(), withException(), assertLogged(), assertLoggedInOrder()) instead + * @deprecated use {@link LogExpectation#info(LogEventMatcher...)} instead */ @Deprecated public FluentLogAssertion.ConfiguredLogAssertion info() { @@ -410,7 +410,7 @@ public FluentLogAssertion.ConfiguredLogAssertion info() { * * @return FluentLogAssertion to assert an debug message * - * @deprecated use the new assertion methods (withMdc(), withException(), assertLogged(), assertLoggedInOrder()) instead + * @deprecated use {@link LogExpectation#debug(LogEventMatcher...)} instead */ @Deprecated public FluentLogAssertion.ConfiguredLogAssertion debug() { @@ -429,7 +429,7 @@ public FluentLogAssertion.ConfiguredLogAssertion debug() { * * @return FluentLogAssertion to assert an trace message * - * @deprecated use the new assertion methods (withMdc(), withException(), assertLogged(), assertLoggedInOrder()) instead + * @deprecated use {@link LogExpectation#trace(LogEventMatcher...)} instead */ @Deprecated public FluentLogAssertion.ConfiguredLogAssertion trace() { From 134001714e12a6db6082abca0370463d3348a791 Mon Sep 17 00:00:00 2001 From: Daniel Flassak Date: Mon, 28 Feb 2022 11:12:46 +0100 Subject: [PATCH 3/3] update Readme and POM for 3.4.1 --- README.md | 5 +++++ pom.xml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index fb2b87f..bff93b2 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ logCapture.assertLoggedInOrder( * [Cucumber example](#cucumber-example) * [Cucumber feature file](#cucumber-feature-file) * [Changes](#changes) + * [3.4.1](#341) * [3.4.0](#340) * [3.3.0](#330) * [3.2.1](#321) @@ -305,6 +306,10 @@ And with MDC logging context ## Changes +### 3.4.1 + +* Improved Javadoc for deprecated methods + ### 3.4.0 * Added `assertNotLogged(...)` for asserting that no matching log message has been logged diff --git a/pom.xml b/pom.xml index b9abab2..60a64f2 100644 --- a/pom.xml +++ b/pom.xml @@ -29,7 +29,7 @@ - 3.4.0-SNAPSHOT + 3.4.1-SNAPSHOT 1.8 1.18.20