Skip to content

Commit a34d7e3

Browse files
committed
Review comments
1 parent ebde6d2 commit a34d7e3

File tree

1 file changed

+19
-11
lines changed
  • http-clients/netty-nio-client/src/main/java/software/amazon/awssdk/http/nio/netty/internal/utils

1 file changed

+19
-11
lines changed

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

+19-11
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,16 @@
2323
import software.amazon.awssdk.annotations.SdkTestInternalApi;
2424

2525
/**
26-
* Logger facade similar to {@link software.amazon.awssdk.utils.Logger}, that also includes the Channel ID in the message when
27-
* provided.
26+
* Logger facade similar to {@link software.amazon.awssdk.utils.Logger}, that also includes channel information in the message
27+
* when provided. When the logger has at least DEBUG level enabled, the logger uses {@link Channel#toString()} to provide the
28+
* complete information about the channel. If only less verbose levels are available, then only the channel's ID is logged.
29+
* <p>
30+
* Having the channel information associated with the log message whenever available makes correlating messages that are all
31+
* logged within the context of that channel possible; this is impossible to do otherwise because there is a 1:M mapping from
32+
* event loops to channels.
33+
* <p>
34+
* <b>NOTE:</b> The absence of overrides that don't take a {@code Channel} parameter is deliberate. This is done to lessen the
35+
* chances that a {code Channel} is omitted from the log by accident.
2836
*/
2937
@SdkInternalApi
3038
public final class NettyClientLogger {
@@ -62,8 +70,8 @@ public void debug(Channel channel, Supplier<String> msgSupplier, Throwable t) {
6270
return;
6371
}
6472

65-
Supplier<String> finalMessage = prependChannelInfo(msgSupplier, channel);
66-
delegateLogger.debug(finalMessage.get(), t);
73+
String finalMessage = prependChannelInfo(msgSupplier, channel);
74+
delegateLogger.debug(finalMessage, t);
6775
}
6876

6977
/**
@@ -88,8 +96,8 @@ public void warn(Channel channel, Supplier<String> msgSupplier, Throwable t) {
8896
return;
8997
}
9098

91-
Supplier<String> finalMessage = prependChannelInfo(msgSupplier, channel);
92-
delegateLogger.warn(finalMessage.get(), t);
99+
String finalMessage = prependChannelInfo(msgSupplier, channel);
100+
delegateLogger.warn(finalMessage, t);
93101
}
94102

95103
/**
@@ -103,13 +111,13 @@ public void trace(Channel channel, Supplier<String> msgSupplier) {
103111
return;
104112
}
105113

106-
Supplier<String> finalMessage = prependChannelInfo(msgSupplier, channel);
107-
delegateLogger.trace(finalMessage.get());
114+
String finalMessage = prependChannelInfo(msgSupplier, channel);
115+
delegateLogger.trace(finalMessage);
108116
}
109117

110-
private Supplier<String> prependChannelInfo(Supplier<String> msgSupplier, Channel channel) {
118+
private String prependChannelInfo(Supplier<String> msgSupplier, Channel channel) {
111119
if (channel == null) {
112-
return msgSupplier;
120+
return msgSupplier.get();
113121
}
114122

115123
String id;
@@ -119,6 +127,6 @@ private Supplier<String> prependChannelInfo(Supplier<String> msgSupplier, Channe
119127
id = channel.toString();
120128
}
121129

122-
return () -> String.format("[Channel: %s] %s", id, msgSupplier.get());
130+
return String.format("[Channel: %s] %s", id, msgSupplier.get());
123131
}
124132
}

0 commit comments

Comments
 (0)