Skip to content

Commit

Permalink
Merge pull request #14 from dm-drogeriemarkt/javadoc
Browse files Browse the repository at this point in the history
Small Javadoc/Readme improvements
  • Loading branch information
cleaning-agent authored Feb 28, 2022
2 parents 10ffa69 + 1340017 commit 68c7e42
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -81,6 +82,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");

Expand All @@ -90,6 +95,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")));
Expand All @@ -109,6 +118,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"));
Expand All @@ -117,6 +130,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"));
Expand Down Expand Up @@ -289,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
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</developers>

<properties>
<project.version>3.4.0-SNAPSHOT</project.version>
<project.version>3.4.1-SNAPSHOT</project.version>

<java.version>1.8</java.version>
<lombok.version>1.18.20</lombok.version>
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/de/dm/infrastructure/logcapture/LogCapture.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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() {
Expand All @@ -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) {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/com/example/app/ReadableApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -504,7 +503,7 @@ void customMdcMatcherSucceeds() {

logCapture.assertLogged(
info("hello",
withMdc("key", mdcValue -> mdcValue.equals("value"))));
mdc("key", mdcValue -> mdcValue.equals("value"))));
}

@Test
Expand Down

0 comments on commit 68c7e42

Please sign in to comment.