JAVA-8405: reducing logging for tutorials-build-job

This commit is contained in:
chaos2418
2021-11-18 11:19:23 +05:30
parent 4ca8e7ef23
commit a62c0f3c8b
81 changed files with 715 additions and 126 deletions

View File

@@ -1,15 +1,20 @@
package com.baeldung.java8.lambda.exceptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.function.Consumer;
public class LambdaExceptionWrappers {
private static final Logger LOGGER = LoggerFactory.getLogger(LambdaExceptionWrappers.class);
public static Consumer<Integer> lambdaWrapper(Consumer<Integer> consumer) {
return i -> {
try {
consumer.accept(i);
} catch (ArithmeticException e) {
System.err.println("Arithmetic Exception occured : " + e.getMessage());
LOGGER.error("Arithmetic Exception occured : {}", e.getMessage());
}
};
}
@@ -21,7 +26,7 @@ public class LambdaExceptionWrappers {
} catch (Exception ex) {
try {
E exCast = clazz.cast(ex);
System.err.println("Exception occured : " + exCast.getMessage());
LOGGER.error("Exception occured : {}", exCast.getMessage());
} catch (ClassCastException ccEx) {
throw ex;
}
@@ -46,7 +51,7 @@ public class LambdaExceptionWrappers {
} catch (Exception ex) {
try {
E exCast = exceptionClass.cast(ex);
System.err.println("Exception occured : " + exCast.getMessage());
LOGGER.error("Exception occured : {}", exCast.getMessage());
} catch (ClassCastException ccEx) {
throw new RuntimeException(ex);
}

View File

@@ -7,14 +7,16 @@ import java.util.function.BiFunction;
import org.apache.commons.lang3.StringUtils;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class MethodReferenceUnitTest {
private static final Logger LOGGER = LoggerFactory.getLogger(MethodReferenceUnitTest.class);
private static <T> void doNothingAtAll(Object... o) {
}
;
@Test
public void referenceToStaticMethod() {
List<String> messages = Arrays.asList("Hello", "Baeldung", "readers!");
@@ -61,7 +63,7 @@ public class MethodReferenceUnitTest {
@Test
public void limitationsAndAdditionalExamples() {
createBicyclesList().forEach(b -> System.out.printf("Bike brand is '%s' and frame size is '%d'%n", b.getBrand(), b.getFrameSize()));
createBicyclesList().forEach(b -> LOGGER.debug("Bike brand is '{}' and frame size is '{}'", b.getBrand(), b.getFrameSize()));
createBicyclesList().forEach((o) -> MethodReferenceUnitTest.doNothingAtAll(o));
}