From b7091fde1a32148b16147d5059acca3925040b67 Mon Sep 17 00:00:00 2001 From: Daniel Flassak Date: Mon, 28 Feb 2022 11:09:58 +0100 Subject: [PATCH] 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() {