Skip to content

Commit 0c958ab

Browse files
committed
Reduce DEBUG logging when running tests
DefaultErrorResponseHandlerTest uses LogCaptor and sets the level of the root logger to DEBUG but never resets it; this has the effect of making all subsequent tests be at DEBUG as well. When combined with tests that also happens to use WireMock, which spits out a ton of debug messages, this results in lots of unnecessary debug log statements. This also adds a jetty-logging.properties test resource to core so that even when we need to temporarily set the root logger to DEBUG, we don't log anything from Jetty/WireMock. Finally, fix some test logging configs that were too verbose. Fixes #396
1 parent b69f581 commit 0c958ab

File tree

3 files changed

+46
-36
lines changed

3 files changed

+46
-36
lines changed

core/src/test/java/software/amazon/awssdk/core/http/DefaultErrorResponseHandlerTest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,16 @@
2323
import static software.amazon.awssdk.core.http.HttpResponseHandler.X_AMZN_REQUEST_ID_HEADER;
2424
import static software.amazon.awssdk.core.internal.http.timers.ClientExecutionAndRequestTimerTestUtils.executionContext;
2525

26+
import java.io.IOException;
2627
import java.util.ArrayList;
2728
import java.util.List;
2829
import java.util.function.Consumer;
2930
import org.apache.commons.lang.RandomStringUtils;
3031
import org.apache.log4j.Level;
3132
import org.apache.log4j.spi.LoggingEvent;
33+
import org.junit.AfterClass;
3234
import org.junit.Before;
35+
import org.junit.BeforeClass;
3336
import org.junit.Test;
3437
import software.amazon.awssdk.core.Request;
3538
import software.amazon.awssdk.core.util.LogCaptor;
@@ -39,12 +42,22 @@
3942
public class DefaultErrorResponseHandlerTest extends WireMockTestBase {
4043

4144
private static final String RESOURCE = "/some-path";
45+
private static LogCaptor logCaptor;
4246
private final AmazonHttpClient client = HttpTestUtils.testAmazonHttpClient();
4347
private final DefaultErrorResponseHandler sut = new DefaultErrorResponseHandler(new ArrayList<>());
44-
private LogCaptor logCaptor = new LogCaptor.DefaultLogCaptor(Level.DEBUG);
48+
49+
@BeforeClass
50+
public static void setup() {
51+
logCaptor = new LogCaptor.DefaultLogCaptor(Level.DEBUG);
52+
}
53+
54+
@AfterClass
55+
public static void teardown() throws Exception {
56+
logCaptor.close();
57+
}
4558

4659
@Before
47-
public void setUp() {
60+
public void methodSetup() {
4861
logCaptor.clear();
4962
}
5063

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Set up logging implementation
2+
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
3+
org.eclipse.jetty.LEVEL=INFO
Lines changed: 28 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,28 @@
1-
#
2-
# Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3-
#
4-
# Licensed under the Apache License, Version 2.0 (the "License").
5-
# You may not use this file except in compliance with the License.
6-
# A copy of the License is located at
7-
#
8-
# http://aws.amazon.com/apache2.0
9-
#
10-
# or in the "license" file accompanying this file. This file is distributed
11-
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12-
# express or implied. See the License for the specific language governing
13-
# permissions and limitations under the License.
14-
#
15-
16-
log4j.rootLogger=DEBUG, A1
17-
log4j.appender.A1=org.apache.log4j.ConsoleAppender
18-
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
19-
20-
# Print the date in ISO 8601 format
21-
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
22-
23-
# Adjust to see more / less logging
24-
log4j.logger.com.amazonaws.ec2=DEBUG
25-
26-
# HttpClient 3 Wire Logging
27-
log4j.logger.httpclient.wire=WARN
28-
29-
# HttpClient 4 Wire Logging
30-
log4j.logger.org.apache.http.wire=WARN
31-
32-
log4j.logger.com.amazonaws=DEBUG
33-
34-
1+
#
2+
# Copyright 2010-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License").
5+
# You may not use this file except in compliance with the License.
6+
# A copy of the License is located at
7+
#
8+
# http://aws.amazon.com/apache2.0
9+
#
10+
# or in the "license" file accompanying this file. This file is distributed
11+
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
# express or implied. See the License for the specific language governing
13+
# permissions and limitations under the License.
14+
#
15+
16+
log4j.rootLogger=WARN, A1
17+
log4j.appender.A1=org.apache.log4j.ConsoleAppender
18+
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
19+
20+
# Print the date in ISO 8601 format
21+
log4j.appender.A1.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
22+
23+
# Adjust to see more / less logging
24+
#log4j.logger.httpclient.wire=TRACE
25+
log4j.logger.com.amazonaws=DEBUG
26+
27+
# HttpClient 4 Wire Logging
28+
log4j.logger.org.apache.http.wire=DEBUG

0 commit comments

Comments
 (0)