23
23
import software .amazon .awssdk .annotations .SdkTestInternalApi ;
24
24
25
25
/**
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.
28
36
*/
29
37
@ SdkInternalApi
30
38
public final class NettyClientLogger {
@@ -62,8 +70,8 @@ public void debug(Channel channel, Supplier<String> msgSupplier, Throwable t) {
62
70
return ;
63
71
}
64
72
65
- Supplier < String > finalMessage = prependChannelInfo (msgSupplier , channel );
66
- delegateLogger .debug (finalMessage . get () , t );
73
+ String finalMessage = prependChannelInfo (msgSupplier , channel );
74
+ delegateLogger .debug (finalMessage , t );
67
75
}
68
76
69
77
/**
@@ -88,8 +96,8 @@ public void warn(Channel channel, Supplier<String> msgSupplier, Throwable t) {
88
96
return ;
89
97
}
90
98
91
- Supplier < String > finalMessage = prependChannelInfo (msgSupplier , channel );
92
- delegateLogger .warn (finalMessage . get () , t );
99
+ String finalMessage = prependChannelInfo (msgSupplier , channel );
100
+ delegateLogger .warn (finalMessage , t );
93
101
}
94
102
95
103
/**
@@ -103,13 +111,13 @@ public void trace(Channel channel, Supplier<String> msgSupplier) {
103
111
return ;
104
112
}
105
113
106
- Supplier < String > finalMessage = prependChannelInfo (msgSupplier , channel );
107
- delegateLogger .trace (finalMessage . get () );
114
+ String finalMessage = prependChannelInfo (msgSupplier , channel );
115
+ delegateLogger .trace (finalMessage );
108
116
}
109
117
110
- private Supplier < String > prependChannelInfo (Supplier <String > msgSupplier , Channel channel ) {
118
+ private String prependChannelInfo (Supplier <String > msgSupplier , Channel channel ) {
111
119
if (channel == null ) {
112
- return msgSupplier ;
120
+ return msgSupplier . get () ;
113
121
}
114
122
115
123
String id ;
@@ -119,6 +127,6 @@ private Supplier<String> prependChannelInfo(Supplier<String> msgSupplier, Channe
119
127
id = channel .toString ();
120
128
}
121
129
122
- return () -> String .format ("[Channel: %s] %s" , id , msgSupplier .get ());
130
+ return String .format ("[Channel: %s] %s" , id , msgSupplier .get ());
123
131
}
124
132
}
0 commit comments