Skip to content

Commit

Permalink
use mdc() instead of withMdc()
Browse files Browse the repository at this point in the history
  • Loading branch information
cleaning-agent committed Dec 5, 2023
1 parent b34851c commit 61a47bf
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
12 changes: 6 additions & 6 deletions src/main/java/de/dm/prom/structuredlogging/MdcContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public static MdcContext of(Object mdcValue) {
*
* @throws E checked exception thrown by callback
*/
public static <T, E extends Throwable> T withMdc(Object mdcValue, MdcSupplier<T, E> supplier) throws E {
public static <T, E extends Throwable> T mdc(Object mdcValue, MdcSupplier<T, E> supplier) throws E {
try (MdcContext c = MdcContext.of(mdcValue)) {
return supplier.get();
}
Expand All @@ -153,7 +153,7 @@ public static <T, E extends Throwable> T withMdc(Object mdcValue, MdcSupplier<T,
*
* @throws E checked exception thrown by callback
*/
public static <E extends Throwable> void withMdc(Object mdcValue, MdcRunnable<E> runnable) throws E {
public static <E extends Throwable> void mdc(Object mdcValue, MdcRunnable<E> runnable) throws E {
try (MdcContext c = MdcContext.of(mdcValue)) {
runnable.run();
}
Expand All @@ -172,7 +172,7 @@ public static <E extends Throwable> void withMdc(Object mdcValue, MdcRunnable<E>
*
* @throws E checked exception thrown by callback
*/
public static <T, E extends Throwable> T withMdc(String mdcKey, Object mdcValue, MdcSupplier<T, E> supplier) throws E {
public static <T, E extends Throwable> T mdc(String mdcKey, Object mdcValue, MdcSupplier<T, E> supplier) throws E {
try (MdcContext c = MdcContext.of(mdcKey, mdcValue)) {
return supplier.get();
}
Expand All @@ -188,7 +188,7 @@ public static <T, E extends Throwable> T withMdc(String mdcKey, Object mdcValue,
*
* @throws E checked exception thrown by callback
*/
public static <E extends Throwable> void withMdc(String mdcKey, Object mdcValue, MdcRunnable<E> runnable) throws E {
public static <E extends Throwable> void mdc(String mdcKey, Object mdcValue, MdcRunnable<E> runnable) throws E {
try (MdcContext c = MdcContext.of(mdcKey, mdcValue)) {
runnable.run();
}
Expand All @@ -209,7 +209,7 @@ public static <E extends Throwable> void withMdc(String mdcKey, Object mdcValue,
*
* @throws E checked exception thrown by callback
*/
public static <T, E extends Throwable, M, S extends MdcKeySupplier<M>> T withMdc(Class<S> keySupplier, M mdcValue, MdcSupplier<T, E> supplier) throws E {
public static <T, E extends Throwable, M, S extends MdcKeySupplier<M>> T mdc(Class<S> keySupplier, M mdcValue, MdcSupplier<T, E> supplier) throws E {
try (MdcContext c = MdcContext.of(keySupplier, mdcValue)) {
return supplier.get();
}
Expand All @@ -227,7 +227,7 @@ public static <T, E extends Throwable, M, S extends MdcKeySupplier<M>> T withMdc
*
* @throws E checked exception thrown by callback
*/
public static <E extends Throwable, M, S extends MdcKeySupplier<M>> void withMdc(Class<S> keySupplier, M mdcValue, MdcRunnable<E> runnable) throws E {
public static <E extends Throwable, M, S extends MdcKeySupplier<M>> void mdc(Class<S> keySupplier, M mdcValue, MdcRunnable<E> runnable) throws E {
try (MdcContext c = MdcContext.of(keySupplier, mdcValue)) {
runnable.run();
}
Expand Down
26 changes: 13 additions & 13 deletions src/test/java/de/dm/prom/structuredlogging/MdcContextUnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import static de.dm.infrastructure.logcapture.ExpectedException.exception;
import static de.dm.infrastructure.logcapture.LogExpectation.error;
import static de.dm.infrastructure.logcapture.LogExpectation.warn;
import static de.dm.prom.structuredlogging.MdcContext.withMdc;
import static de.dm.prom.structuredlogging.MdcContext.mdc;
import static de.dm.prom.structuredlogging.StructuredMdcJsonProvider.JSON_PREFIX;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
Expand Down Expand Up @@ -62,14 +62,14 @@ void withTryBlock() throws IOException {

@Test
void withRunnable() throws IOException {
withMdc(ExampleBeanKeySupplier.class, ExampleBean.getExample(), () ->
mdc(ExampleBeanKeySupplier.class, ExampleBean.getExample(), () ->
assertMdcFieldContentIsCorrect("example_bean", SAMPLE_BEAN_JSON));
}

@Test
void withThrowingRunnable() {
try {
withMdc(ExampleBeanKeySupplier.class, ExampleBean.getExample(), () -> {
mdc(ExampleBeanKeySupplier.class, ExampleBean.getExample(), () -> {
assertMdcFieldContentIsCorrect("example_bean", SAMPLE_BEAN_JSON);
throwIOException();
});
Expand All @@ -81,7 +81,7 @@ void withThrowingRunnable() {

@Test
void withSupplier() throws IOException {
var actual = withMdc(ExampleBeanKeySupplier.class, ExampleBean.getExample(), () -> {
var actual = mdc(ExampleBeanKeySupplier.class, ExampleBean.getExample(), () -> {
assertMdcFieldContentIsCorrect("example_bean", SAMPLE_BEAN_JSON);
return 42;
});
Expand All @@ -91,7 +91,7 @@ void withSupplier() throws IOException {
@Test
void withThrowingSupplier() {
try {
withMdc(ExampleBeanKeySupplier.class, ExampleBean.getExample(), () -> {
mdc(ExampleBeanKeySupplier.class, ExampleBean.getExample(), () -> {
assertMdcFieldContentIsCorrect("example_bean", SAMPLE_BEAN_JSON);
throwIOException();
return 42;
Expand All @@ -114,14 +114,14 @@ void withTryBlock() throws IOException {

@Test
void withRunnable() throws IOException {
withMdc(ExampleBean.getExample(), () ->
mdc(ExampleBean.getExample(), () ->
assertMdcFieldContentIsCorrect("ExampleBean", SAMPLE_BEAN_JSON));
}

@Test
void withThrowingRunnable() {
try {
withMdc(ExampleBean.getExample(), () -> {
mdc(ExampleBean.getExample(), () -> {
assertMdcFieldContentIsCorrect("ExampleBean", SAMPLE_BEAN_JSON);
throwIOException();
});
Expand All @@ -133,7 +133,7 @@ void withThrowingRunnable() {

@Test
void withSupplier() throws IOException {
var actual = withMdc(ExampleBean.getExample(), () -> {
var actual = mdc(ExampleBean.getExample(), () -> {
assertMdcFieldContentIsCorrect("ExampleBean", SAMPLE_BEAN_JSON);
return 42;
});
Expand All @@ -143,7 +143,7 @@ void withSupplier() throws IOException {
@Test
void withThrowingSupplier() {
try {
withMdc(ExampleBean.getExample(), () -> {
mdc(ExampleBean.getExample(), () -> {
assertMdcFieldContentIsCorrect("ExampleBean", SAMPLE_BEAN_JSON);
throwIOException();
return 42;
Expand All @@ -166,14 +166,14 @@ void withTryBlock() throws IOException {

@Test
void withRunnable() throws IOException {
withMdc("explicit_key", ExampleBean.getExample(), () ->
mdc("explicit_key", ExampleBean.getExample(), () ->
assertMdcFieldContentIsCorrect("explicit_key", SAMPLE_BEAN_JSON));
}

@Test
void withThrowingRunnable() {
try {
withMdc("explicit_key", ExampleBean.getExample(), () -> {
mdc("explicit_key", ExampleBean.getExample(), () -> {
assertMdcFieldContentIsCorrect("explicit_key", SAMPLE_BEAN_JSON);
throwIOException();
});
Expand All @@ -185,7 +185,7 @@ void withThrowingRunnable() {

@Test
void withSupplier() throws IOException {
var actual = withMdc("explicit_key", ExampleBean.getExample(), () -> {
var actual = mdc("explicit_key", ExampleBean.getExample(), () -> {
assertMdcFieldContentIsCorrect("explicit_key", SAMPLE_BEAN_JSON);
return 42;
});
Expand All @@ -195,7 +195,7 @@ void withSupplier() throws IOException {
@Test
void withThrowingSupplier() {
try {
withMdc("explicit_key", ExampleBean.getExample(), () -> {
mdc("explicit_key", ExampleBean.getExample(), () -> {
assertMdcFieldContentIsCorrect("explicit_key", SAMPLE_BEAN_JSON);
throwIOException();
return 42;
Expand Down

0 comments on commit 61a47bf

Please sign in to comment.