Skip to content

Commit 30d98c2

Browse files
authored
Use NettyClientLogger everywhere (#2932)
1 parent f6aebd8 commit 30d98c2

25 files changed

+242
-111
lines changed

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/NettyNioAsyncHttpClient.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
import static software.amazon.awssdk.http.nio.netty.internal.NettyConfiguration.EVENTLOOP_SHUTDOWN_FUTURE_TIMEOUT_SECONDS;
2020
import static software.amazon.awssdk.http.nio.netty.internal.NettyConfiguration.EVENTLOOP_SHUTDOWN_QUIET_PERIOD_SECONDS;
2121
import static software.amazon.awssdk.http.nio.netty.internal.NettyConfiguration.EVENTLOOP_SHUTDOWN_TIMEOUT_SECONDS;
22+
import static software.amazon.awssdk.http.nio.netty.internal.utils.NettyUtils.runAndLogError;
2223
import static software.amazon.awssdk.utils.FunctionalUtils.invokeSafely;
23-
import static software.amazon.awssdk.utils.FunctionalUtils.runAndLogError;
2424

2525
import io.netty.channel.ChannelOption;
2626
import io.netty.channel.EventLoopGroup;
@@ -34,8 +34,6 @@
3434
import java.util.concurrent.TimeUnit;
3535
import java.util.concurrent.TimeoutException;
3636
import java.util.function.Consumer;
37-
import org.slf4j.Logger;
38-
import org.slf4j.LoggerFactory;
3937
import software.amazon.awssdk.annotations.SdkPublicApi;
4038
import software.amazon.awssdk.annotations.SdkTestInternalApi;
4139
import software.amazon.awssdk.http.Protocol;
@@ -55,6 +53,7 @@
5553
import software.amazon.awssdk.http.nio.netty.internal.SdkChannelPool;
5654
import software.amazon.awssdk.http.nio.netty.internal.SdkChannelPoolMap;
5755
import software.amazon.awssdk.http.nio.netty.internal.SharedSdkEventLoopGroup;
56+
import software.amazon.awssdk.http.nio.netty.internal.utils.NettyClientLogger;
5857
import software.amazon.awssdk.utils.AttributeMap;
5958
import software.amazon.awssdk.utils.Either;
6059
import software.amazon.awssdk.utils.Validate;
@@ -69,7 +68,7 @@ public final class NettyNioAsyncHttpClient implements SdkAsyncHttpClient {
6968

7069
private static final String CLIENT_NAME = "NettyNio";
7170

72-
private static final Logger log = LoggerFactory.getLogger(NettyNioAsyncHttpClient.class);
71+
private static final NettyClientLogger log = NettyClientLogger.getLogger(NettyNioAsyncHttpClient.class);
7372
private static final long MAX_STREAMS_ALLOWED = 4294967295L; // unsigned 32-bit, 2^32 -1
7473
private static final int DEFAULT_INITIAL_WINDOW_SIZE = 1_048_576; // 1MiB
7574

@@ -210,7 +209,7 @@ private void closeEventLoopUninterruptibly(EventLoopGroup eventLoopGroup) throws
210209
Thread.currentThread().interrupt();
211210
throw new RuntimeException(e);
212211
} catch (TimeoutException e) {
213-
log.error(String.format("Shutting down Netty EventLoopGroup did not complete within %s seconds",
212+
log.error(null, () -> String.format("Shutting down Netty EventLoopGroup did not complete within %s seconds",
214213
EVENTLOOP_SHUTDOWN_FUTURE_TIMEOUT_SECONDS));
215214
}
216215
}

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/AwaitCloseChannelPoolMap.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@
4242
import software.amazon.awssdk.http.nio.netty.ProxyConfiguration;
4343
import software.amazon.awssdk.http.nio.netty.SdkEventLoopGroup;
4444
import software.amazon.awssdk.http.nio.netty.internal.http2.HttpOrHttp2ChannelPool;
45-
import software.amazon.awssdk.utils.Logger;
45+
import software.amazon.awssdk.http.nio.netty.internal.utils.NettyClientLogger;
4646

4747
/**
4848
* Implementation of {@link SdkChannelPoolMap} that awaits channel pools to be closed upon closing.
4949
*/
5050
@SdkInternalApi
5151
public final class AwaitCloseChannelPoolMap extends SdkChannelPoolMap<URI, SimpleChannelPoolAwareChannelPool> {
5252

53-
private static final Logger log = Logger.loggerFor(AwaitCloseChannelPoolMap.class);
53+
private static final NettyClientLogger log = NettyClientLogger.getLogger(AwaitCloseChannelPoolMap.class);
5454

5555
private static final ChannelPoolHandler NOOP_HANDLER = new ChannelPoolHandler() {
5656
@Override
@@ -153,7 +153,7 @@ protected SimpleChannelPoolAwareChannelPool newPool(URI key) {
153153

154154
@Override
155155
public void close() {
156-
log.trace(() -> "Closing channel pools");
156+
log.trace(null, () -> "Closing channel pools");
157157
// If there is a new pool being added while we are iterating the pools, there might be a
158158
// race condition between the close call of the newly acquired pool and eventLoopGroup.shutdown and it
159159
// could cause the eventLoopGroup#shutdownGracefully to hang before it times out.

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/FutureCancelHandler.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,15 @@
2323
import io.netty.channel.ChannelInboundHandlerAdapter;
2424
import java.io.IOException;
2525
import software.amazon.awssdk.annotations.SdkInternalApi;
26-
import software.amazon.awssdk.utils.Logger;
26+
import software.amazon.awssdk.http.nio.netty.internal.utils.NettyClientLogger;
2727

2828
/**
2929
* Closes the channel if the execution future has been cancelled.
3030
*/
3131
@SdkInternalApi
3232
@ChannelHandler.Sharable
3333
public final class FutureCancelHandler extends ChannelInboundHandlerAdapter {
34-
private static final Logger LOG = Logger.loggerFor(FutureCancelHandler.class);
34+
private static final NettyClientLogger LOG = NettyClientLogger.getLogger(FutureCancelHandler.class);
3535
private static final FutureCancelHandler INSTANCE = new FutureCancelHandler();
3636

3737
private FutureCancelHandler() {
@@ -53,9 +53,9 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable e) {
5353
ctx.close();
5454
requestContext.channelPool().release(ctx.channel());
5555
} else {
56-
LOG.debug(() -> String.format("Received a cancellation exception but it did not match the current execution ID. "
57-
+ "Exception's execution ID is %d, but the current ID on the channel is %d. Exception"
58-
+ " is being ignored.",
56+
LOG.debug(ctx.channel(), () -> String.format("Received a cancellation exception but it did not match the current "
57+
+ "execution ID. Exception's execution ID is %d, but the current ID on "
58+
+ "the channel is %d. Exception is being ignored.",
5959
cancelledException.getExecutionId(),
6060
executionId(ctx)));
6161
}

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/HonorCloseOnReleaseChannelPool.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import io.netty.util.concurrent.Future;
2323
import io.netty.util.concurrent.Promise;
2424
import software.amazon.awssdk.annotations.SdkInternalApi;
25-
import software.amazon.awssdk.utils.Logger;
25+
import software.amazon.awssdk.http.nio.netty.internal.utils.NettyClientLogger;
2626

2727
/**
2828
* Wrap a channel pool so that {@link ChannelAttributeKey#CLOSE_ON_RELEASE} is honored when a channel is released to the
@@ -33,7 +33,7 @@
3333
*/
3434
@SdkInternalApi
3535
public class HonorCloseOnReleaseChannelPool implements ChannelPool {
36-
private static final Logger log = Logger.loggerFor(HonorCloseOnReleaseChannelPool.class);
36+
private static final NettyClientLogger log = NettyClientLogger.getLogger(HonorCloseOnReleaseChannelPool.class);
3737
private final ChannelPool delegatePool;
3838

3939
public HonorCloseOnReleaseChannelPool(ChannelPool delegatePool) {
@@ -61,7 +61,7 @@ public Future<Void> release(Channel channel, Promise<Void> promise) {
6161
boolean shouldCloseOnRelease = Boolean.TRUE.equals(channel.attr(ChannelAttributeKey.CLOSE_ON_RELEASE).get());
6262

6363
if (shouldCloseOnRelease && channel.isOpen() && !channel.eventLoop().isShuttingDown()) {
64-
log.debug(() -> "Closing connection (" + channel.id() + "), instead of releasing it.");
64+
log.debug(channel, () -> "Closing connection (" + channel.id() + "), instead of releasing it.");
6565
channel.close();
6666
}
6767

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/Http1TunnelConnectionPool.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
import java.net.URI;
3232
import software.amazon.awssdk.annotations.SdkInternalApi;
3333
import software.amazon.awssdk.annotations.SdkTestInternalApi;
34+
import software.amazon.awssdk.http.nio.netty.internal.utils.NettyClientLogger;
3435
import software.amazon.awssdk.http.nio.netty.internal.utils.NettyUtils;
35-
import software.amazon.awssdk.utils.Logger;
3636
import software.amazon.awssdk.utils.StringUtils;
3737

3838
/**
@@ -43,7 +43,7 @@ public class Http1TunnelConnectionPool implements ChannelPool {
4343
static final AttributeKey<Boolean> TUNNEL_ESTABLISHED_KEY = NettyUtils.getOrCreateAttributeKey(
4444
"aws.http.nio.netty.async.Http1TunnelConnectionPool.tunnelEstablished");
4545

46-
private static final Logger log = Logger.loggerFor(Http1TunnelConnectionPool.class);
46+
private static final NettyClientLogger log = NettyClientLogger.getLogger(Http1TunnelConnectionPool.class);
4747

4848
private final EventLoop eventLoop;
4949
private final ChannelPool delegate;
@@ -124,13 +124,13 @@ public void close() {
124124

125125
private void setupChannel(Channel ch, Promise<Channel> acquirePromise) {
126126
if (isTunnelEstablished(ch)) {
127-
log.debug(() -> String.format("Tunnel already established for %s", ch.id().asShortText()));
127+
log.debug(ch, () -> String.format("Tunnel already established for %s", ch.id().asShortText()));
128128
acquirePromise.setSuccess(ch);
129129
return;
130130
}
131131

132-
log.debug(() -> String.format("Tunnel not yet established for channel %s. Establishing tunnel now.",
133-
ch.id().asShortText()));
132+
log.debug(ch, () -> String.format("Tunnel not yet established for channel %s. Establishing tunnel now.",
133+
ch.id().asShortText()));
134134

135135
Promise<Channel> tunnelEstablishedPromise = eventLoop.newPromise();
136136

@@ -151,7 +151,7 @@ private void setupChannel(Channel ch, Promise<Channel> acquirePromise) {
151151
delegate.release(ch);
152152

153153
Throwable cause = f.cause();
154-
log.error(() -> String.format("Unable to establish tunnel for channel %s", ch.id().asShortText()), cause);
154+
log.error(ch, () -> String.format("Unable to establish tunnel for channel %s", ch.id().asShortText()), cause);
155155
acquirePromise.setFailure(cause);
156156
}
157157
});

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/IdleConnectionCountingChannelPool.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@
2727
import java.util.concurrent.CompletableFuture;
2828
import software.amazon.awssdk.annotations.SdkInternalApi;
2929
import software.amazon.awssdk.http.HttpMetric;
30+
import software.amazon.awssdk.http.nio.netty.internal.utils.NettyClientLogger;
3031
import software.amazon.awssdk.http.nio.netty.internal.utils.NettyUtils;
3132
import software.amazon.awssdk.metrics.MetricCollector;
32-
import software.amazon.awssdk.utils.Logger;
3333

3434
/**
3535
* A channel pool implementation that tracks the number of "idle" channels in an underlying channel pool.
@@ -39,7 +39,7 @@
3939
*/
4040
@SdkInternalApi
4141
public class IdleConnectionCountingChannelPool implements SdkChannelPool {
42-
private static final Logger log = Logger.loggerFor(IdleConnectionCountingChannelPool.class);
42+
private static final NettyClientLogger log = NettyClientLogger.getLogger(IdleConnectionCountingChannelPool.class);
4343

4444
/**
4545
* The idle channel state for a specific channel. This should only be accessed from the {@link #executor}.
@@ -147,8 +147,8 @@ private void channelAcquired(Channel channel) {
147147
break;
148148
case NOT_IDLE:
149149
default:
150-
log.warn(() -> "Failed to update idle connection count metric on acquire, because the channel (" +
151-
channel + ") was in an unexpected state: " + channelIdleState);
150+
log.warn(channel, () -> "Failed to update idle connection count metric on acquire, because the channel "
151+
+ "(" + channel + ") was in an unexpected state: " + channelIdleState);
152152
}
153153
}
154154
});
@@ -162,7 +162,8 @@ private Future<?> channelReleased(Channel channel) {
162162
ChannelIdleState channelIdleState = getChannelIdleState(channel);
163163

164164
if (channelIdleState == null) {
165-
log.warn(() -> "Failed to update idle connection count metric on release, because the channel (" + channel +
165+
log.warn(channel,
166+
() -> "Failed to update idle connection count metric on release, because the channel (" + channel +
166167
") was in an unexpected state: null");
167168
} else {
168169
switch (channelIdleState) {
@@ -174,8 +175,8 @@ private Future<?> channelReleased(Channel channel) {
174175
break;
175176
case IDLE:
176177
default:
177-
log.warn(() -> "Failed to update idle connection count metric on release, because the channel (" +
178-
channel + ") was in an unexpected state: " + channelIdleState);
178+
log.warn(channel, () -> "Failed to update idle connection count metric on release, because the channel "
179+
+ "(" + channel + ") was in an unexpected state: " + channelIdleState);
179180
}
180181
}
181182
});
@@ -197,7 +198,8 @@ private void channelClosed(Channel channel) {
197198
case NOT_IDLE:
198199
break;
199200
default:
200-
log.warn(() -> "Failed to update idle connection count metric on close, because the channel (" + channel +
201+
log.warn(channel,
202+
() -> "Failed to update idle connection count metric on close, because the channel (" + channel +
201203
") was in an unexpected state: " + channelIdleState);
202204
}
203205
}
@@ -217,15 +219,15 @@ private void setChannelIdleState(Channel channel, ChannelIdleState newState) {
217219
*/
218220
private void decrementIdleConnections() {
219221
--idleConnections;
220-
log.trace(() -> "Idle connection count decremented, now " + idleConnections);
222+
log.trace(null, () -> "Idle connection count decremented, now " + idleConnections);
221223
}
222224

223225
/**
224226
* Increment the idle connection count. This must be invoked from the {@link #executor}.
225227
*/
226228
private void incrementIdleConnections() {
227229
++idleConnections;
228-
log.trace(() -> "Idle connection count incremented, now " + idleConnections);
230+
log.trace(null, () -> "Idle connection count incremented, now " + idleConnections);
229231
}
230232

231233
/**

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/IdleConnectionReaperHandler.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020
import io.netty.handler.timeout.IdleStateHandler;
2121
import java.util.concurrent.TimeUnit;
2222
import software.amazon.awssdk.annotations.SdkInternalApi;
23-
import software.amazon.awssdk.utils.Logger;
23+
import software.amazon.awssdk.http.nio.netty.internal.utils.NettyClientLogger;
2424

2525
/**
2626
* A handler that closes unused channels that have not had any traffic on them for a configurable amount of time.
2727
*/
2828
@SdkInternalApi
2929
public class IdleConnectionReaperHandler extends IdleStateHandler {
30-
private static final Logger log = Logger.loggerFor(IdleConnectionReaperHandler.class);
30+
private static final NettyClientLogger log = NettyClientLogger.getLogger(IdleConnectionReaperHandler.class);
3131
private final int maxIdleTimeMillis;
3232

3333
public IdleConnectionReaperHandler(int maxIdleTimeMillis) {
@@ -42,8 +42,8 @@ protected void channelIdle(ChannelHandlerContext ctx, IdleStateEvent event) {
4242
boolean channelNotInUse = Boolean.FALSE.equals(ctx.channel().attr(ChannelAttributeKey.IN_USE).get());
4343

4444
if (channelNotInUse && ctx.channel().isOpen()) {
45-
log.debug(() -> "Closing unused connection (" + ctx.channel().id() + ") because it has been idle for longer than " +
46-
maxIdleTimeMillis + " milliseconds.");
45+
log.debug(ctx.channel(), () -> "Closing unused connection (" + ctx.channel().id() + ") because it has been idle for "
46+
+ "longer than " + maxIdleTimeMillis + " milliseconds.");
4747
ctx.close();
4848
}
4949
}

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/LastHttpContentHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import io.netty.channel.ChannelInboundHandlerAdapter;
2323
import io.netty.handler.codec.http.LastHttpContent;
2424
import software.amazon.awssdk.annotations.SdkInternalApi;
25-
import software.amazon.awssdk.utils.Logger;
25+
import software.amazon.awssdk.http.nio.netty.internal.utils.NettyClientLogger;
2626

2727
/**
2828
* Marks {@code ChannelAttributeKey.LAST_HTTP_CONTENT_RECEIVED_KEY} if {@link LastHttpContent} is received.
@@ -31,12 +31,12 @@
3131
@ChannelHandler.Sharable
3232
public final class LastHttpContentHandler extends ChannelInboundHandlerAdapter {
3333
private static final LastHttpContentHandler INSTANCE = new LastHttpContentHandler();
34-
private static final Logger logger = Logger.loggerFor(LastHttpContent.class);
34+
private static final NettyClientLogger logger = NettyClientLogger.getLogger(LastHttpContent.class);
3535

3636
@Override
3737
public void channelRead(ChannelHandlerContext ctx, Object msg) {
3838
if (msg instanceof LastHttpContent) {
39-
logger.debug(() -> "Received LastHttpContent " + ctx.channel());
39+
logger.debug(ctx.channel(), () -> "Received LastHttpContent " + ctx.channel());
4040
ctx.channel().attr(LAST_HTTP_CONTENT_RECEIVED_KEY).set(true);
4141
}
4242

http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/OldConnectionReaperHandler.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import io.netty.util.concurrent.ScheduledFuture;
2121
import java.util.concurrent.TimeUnit;
2222
import software.amazon.awssdk.annotations.SdkInternalApi;
23-
import software.amazon.awssdk.utils.Logger;
23+
import software.amazon.awssdk.http.nio.netty.internal.utils.NettyClientLogger;
2424
import software.amazon.awssdk.utils.Validate;
2525

2626
/**
@@ -31,7 +31,7 @@
3131
*/
3232
@SdkInternalApi
3333
public class OldConnectionReaperHandler extends ChannelDuplexHandler {
34-
private static final Logger log = Logger.loggerFor(OldConnectionReaperHandler.class);
34+
private static final NettyClientLogger log = NettyClientLogger.getLogger(OldConnectionReaperHandler.class);
3535
private final int connectionTtlMillis;
3636

3737
private ScheduledFuture<?> channelKiller;
@@ -84,12 +84,13 @@ private void closeChannel(ChannelHandlerContext ctx) {
8484

8585
if (ctx.channel().isOpen()) {
8686
if (Boolean.FALSE.equals(ctx.channel().attr(ChannelAttributeKey.IN_USE).get())) {
87-
log.debug(() -> "Closing unused connection (" + ctx.channel().id() + ") because it has reached its maximum " +
88-
"time to live of " + connectionTtlMillis + " milliseconds.");
87+
log.debug(ctx.channel(), () -> "Closing unused connection (" + ctx.channel().id() + ") because it has reached "
88+
+ "its maximum time to live of " + connectionTtlMillis + " milliseconds.");
8989
ctx.close();
9090
} else {
91-
log.debug(() -> "Connection (" + ctx.channel().id() + ") will be closed during its next release, because it " +
92-
"has reached its maximum time to live of " + connectionTtlMillis + " milliseconds.");
91+
log.debug(ctx.channel(), () -> "Connection (" + ctx.channel().id() + ") will be closed during its next release, "
92+
+ "because it has reached its maximum time to live of " + connectionTtlMillis
93+
+ " milliseconds.");
9394
ctx.channel().attr(ChannelAttributeKey.CLOSE_ON_RELEASE).set(true);
9495
}
9596
}

0 commit comments

Comments
 (0)