Skip to content

Commit 66afe45

Browse files
authored
[JAVA-44946] Reduce logging (#18382)
1 parent 3c5ad81 commit 66afe45

File tree

14 files changed

+109
-9
lines changed

14 files changed

+109
-9
lines changed

apache-httpclient-2/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,15 @@
6666
<target>11</target>
6767
</configuration>
6868
</plugin>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-surefire-plugin</artifactId>
72+
<configuration>
73+
<systemPropertyVariables>
74+
<mockserver.logLevel>ERROR</mockserver.logLevel>
75+
</systemPropertyVariables>
76+
</configuration>
77+
</plugin>
6978
</plugins>
7079
</build>
7180

apache-httpclient/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@
8282
<target>11</target>
8383
</configuration>
8484
</plugin>
85+
<plugin>
86+
<groupId>org.apache.maven.plugins</groupId>
87+
<artifactId>maven-surefire-plugin</artifactId>
88+
<configuration>
89+
<systemPropertyVariables>
90+
<mockserver.logLevel>ERROR</mockserver.logLevel>
91+
</systemPropertyVariables>
92+
</configuration>
93+
</plugin>
8594
</plugins>
8695
<resources>
8796
<resource>

apache-httpclient/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpClientUnitTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33

44
import org.junit.jupiter.api.Test;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
57

68
import java.io.IOException;
79
import java.net.URI;
@@ -10,6 +12,7 @@
1012
import java.net.http.HttpResponse;
1113

1214
class HttpClientUnitTest {
15+
private final Logger logger = LoggerFactory.getLogger(getClass());
1316
public static final String DUMMY_URL = "https://postman-echo.com/get";
1417

1518
@Test
@@ -19,12 +22,12 @@ void whenUseHttpClient_thenCorrect() throws IOException, InterruptedException {
1922

2023
// synchronous response
2124
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
22-
System.out.println(response.body());
25+
logger.debug(response.body());
2326

2427
// asynchronous response
2528
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
2629
.thenApply(HttpResponse::body)
27-
.thenAccept(System.out::println)
30+
.thenAccept(logger::debug)
2831
.join();
2932
}
3033
}

apache-httpclient/src/test/java/com/baeldung/httpclient/readresponsebodystring/HttpUrlConnectionUnitTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33

44
import org.junit.jupiter.api.Test;
5+
import org.slf4j.Logger;
6+
import org.slf4j.LoggerFactory;
57

68
import java.io.BufferedReader;
79
import java.io.IOException;
@@ -14,7 +16,7 @@
1416
import static org.junit.jupiter.api.Assertions.assertNotNull;
1517

1618
public class HttpUrlConnectionUnitTest {
17-
19+
private final Logger logger = LoggerFactory.getLogger(getClass());
1820
public static final String DUMMY_URL = "https://postman-echo.com/get";
1921

2022
@Test
@@ -32,6 +34,6 @@ void whenUseHttpUrlConnection_thenCorrect() throws IOException, URISyntaxExcepti
3234

3335
in.close();
3436
assertNotNull(response.toString());
35-
System.out.println("Response -> " + response.toString());
37+
logger.debug("Response -> {}", response.toString());
3638
}
3739
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
package com.baeldung.httpclient.readresponsebodystring;
22

33
import org.junit.jupiter.api.Test;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
46
import org.springframework.web.client.RestTemplate;
57

68
public class SpringRestTemplateUnitTest {
7-
9+
private final Logger logger = LoggerFactory.getLogger(getClass());
810
public static final String DUMMY_URL = "https://postman-echo.com/get";
911

1012
@Test
1113
public void whenUseRestTemplate_thenCorrect() {
1214
RestTemplate restTemplate = new RestTemplate();
1315
String response = restTemplate.getForObject(DUMMY_URL, String.class);
14-
System.out.println(response);
16+
logger.debug(response);
1517
}
1618

1719
}
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
package com.baeldung.httpclient.readresponsebodystring;
22

33
import org.junit.jupiter.api.Test;
4+
import org.slf4j.Logger;
5+
import org.slf4j.LoggerFactory;
46
import org.springframework.web.reactive.function.client.WebClient;
57
import reactor.core.publisher.Mono;
68

79
public class SpringWebClientUnitTest {
10+
private final Logger logger = LoggerFactory.getLogger(getClass());
811
public static final String DUMMY_URL = "https://postman-echo.com/get";
912

1013
@Test
1114
void whenUseWebClientRetrieve_thenCorrect() {
1215
WebClient webClient = WebClient.create(DUMMY_URL);
1316
Mono<String> body = webClient.get().retrieve().bodyToMono(String.class);
1417
String s = body.block();
15-
System.out.println(s);
18+
logger.debug(s);
1619
}
1720
}

apache-httpclient4/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,17 @@
192192
<filtering>true</filtering>
193193
</resource>
194194
</resources>
195+
<plugins>
196+
<plugin>
197+
<groupId>org.apache.maven.plugins</groupId>
198+
<artifactId>maven-surefire-plugin</artifactId>
199+
<configuration>
200+
<systemPropertyVariables>
201+
<mockserver.logLevel>ERROR</mockserver.logLevel>
202+
</systemPropertyVariables>
203+
</configuration>
204+
</plugin>
205+
</plugins>
195206
</build>
196207

197208
<profiles>

apache-kafka-2/pom.xml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,20 @@
119119
</dependency>
120120
</dependencies>
121121

122+
<build>
123+
<plugins>
124+
<plugin>
125+
<groupId>org.apache.maven.plugins</groupId>
126+
<artifactId>maven-surefire-plugin</artifactId>
127+
<configuration>
128+
<systemPropertyVariables>
129+
<logback.configurationFile>src/test/resources/logback.xml</logback.configurationFile>
130+
</systemPropertyVariables>
131+
</configuration>
132+
</plugin>
133+
</plugins>
134+
</build>
135+
122136
<properties>
123137
<jna.version>5.7.0</jna.version>
124138
<kafka.version>3.9.0</kafka.version>

apache-kafka-2/src/test/resources/logback.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
55
</encoder>
66
</appender>
7+
<logger name="org.apache.flink" level="ERROR"/>
8+
<logger name="org.apache.kafka" level="ERROR"/>
79

810
<root level="INFO">
911
<appender-ref ref="STDOUT" />

apache-libraries-2/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,15 @@
235235
<target>${maven.compiler.target}</target>
236236
</configuration>
237237
</plugin>
238+
<plugin>
239+
<groupId>org.apache.maven.plugins</groupId>
240+
<artifactId>maven-surefire-plugin</artifactId>
241+
<configuration>
242+
<systemPropertyVariables>
243+
<logback.configurationFile>src/test/resources/logback-test.xml</logback.configurationFile>
244+
</systemPropertyVariables>
245+
</configuration>
246+
</plugin>
238247
</plugins>
239248
</build>
240249

0 commit comments

Comments
 (0)