Skip to content

Commit 94f7601

Browse files
authored
Hide TransportChannel#logger (#80868)
In #57573 we introduced a `public static Logger logger` field in `TransportChannel` which some IDEs tend to automatically import if you mention an as-yet-undeclared `logger` field. This commit reverts that small part of #57573 so that we go back to using a private logger belonging to `ChannelActionListener` instead.
1 parent 6b2685f commit 94f7601

File tree

2 files changed

+14
-21
lines changed

2 files changed

+14
-21
lines changed

server/src/main/java/org/elasticsearch/action/support/ChannelActionListener.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
package org.elasticsearch.action.support;
1010

11+
import org.apache.logging.log4j.LogManager;
12+
import org.apache.logging.log4j.Logger;
13+
import org.apache.logging.log4j.message.ParameterizedMessage;
1114
import org.elasticsearch.action.ActionListener;
1215
import org.elasticsearch.transport.TransportChannel;
1316
import org.elasticsearch.transport.TransportRequest;
@@ -17,6 +20,8 @@ public final class ChannelActionListener<Response extends TransportResponse, Req
1720
implements
1821
ActionListener<Response> {
1922

23+
private static final Logger logger = LogManager.getLogger();
24+
2025
private final TransportChannel channel;
2126
private final Request request;
2227
private final String actionName;
@@ -38,7 +43,15 @@ public void onResponse(Response response) {
3843

3944
@Override
4045
public void onFailure(Exception e) {
41-
TransportChannel.sendErrorResponse(channel, actionName, request, e);
46+
try {
47+
channel.sendResponse(e);
48+
} catch (Exception sendException) {
49+
sendException.addSuppressed(e);
50+
logger.warn(
51+
() -> new ParameterizedMessage("Failed to send error response for action [{}] and request [{}]", actionName, request),
52+
sendException
53+
);
54+
}
4255
}
4356

4457
@Override

server/src/main/java/org/elasticsearch/transport/TransportChannel.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@
88

99
package org.elasticsearch.transport;
1010

11-
import org.apache.logging.log4j.LogManager;
12-
import org.apache.logging.log4j.Logger;
13-
import org.apache.logging.log4j.message.ParameterizedMessage;
1411
import org.elasticsearch.Version;
1512

1613
import java.io.IOException;
@@ -20,8 +17,6 @@
2017
*/
2118
public interface TransportChannel {
2219

23-
Logger logger = LogManager.getLogger(TransportChannel.class);
24-
2520
String getProfileName();
2621

2722
String getChannelType();
@@ -36,19 +31,4 @@ public interface TransportChannel {
3631
default Version getVersion() {
3732
return Version.CURRENT;
3833
}
39-
40-
/**
41-
* A helper method to send an exception and handle and log a subsequent exception
42-
*/
43-
static void sendErrorResponse(TransportChannel channel, String actionName, TransportRequest request, Exception e) {
44-
try {
45-
channel.sendResponse(e);
46-
} catch (Exception sendException) {
47-
sendException.addSuppressed(e);
48-
logger.warn(
49-
() -> new ParameterizedMessage("Failed to send error response for action [{}] and request [{}]", actionName, request),
50-
sendException
51-
);
52-
}
53-
}
5434
}

0 commit comments

Comments
 (0)