Skip to content

Commit 91de5f7

Browse files
committed
Add to LogGrpcInterceptor example logging for all grpc data for DEBUG logging level. SpotlessApply
1 parent 641c5dc commit 91de5f7

File tree

2 files changed

+44
-40
lines changed

2 files changed

+44
-40
lines changed

examples/cloud-grpc-client/src/main/java/net/devh/boot/grpc/examples/cloud/client/LogGrpcInterceptor.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package net.devh.boot.grpc.examples.cloud.client;
1919

20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
2023
import io.grpc.CallOptions;
2124
import io.grpc.Channel;
2225
import io.grpc.ClientCall;
@@ -26,8 +29,6 @@
2629
import io.grpc.Metadata;
2730
import io.grpc.MethodDescriptor;
2831
import io.grpc.Status;
29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
3132
import net.devh.boot.grpc.client.interceptor.GrpcGlobalClientInterceptor;
3233

3334
/**
@@ -58,26 +59,27 @@ public void sendMessage(ReqT message) {
5859

5960
@Override
6061
public void start(Listener<RespT> responseListener, Metadata headers) {
61-
super.start(new ForwardingClientCallListener.SimpleForwardingClientCallListener<RespT>(responseListener) {
62-
@Override
63-
public void onMessage(RespT message) {
64-
log.debug("Response message: \n{}", message.toString());
65-
super.onMessage(message);
66-
}
62+
super.start(
63+
new ForwardingClientCallListener.SimpleForwardingClientCallListener<RespT>(responseListener) {
64+
@Override
65+
public void onMessage(RespT message) {
66+
log.debug("Response message: \n{}", message.toString());
67+
super.onMessage(message);
68+
}
6769

68-
@Override
69-
public void onHeaders(Metadata headers) {
70-
log.debug("gRPC headers: \n{}", headers.toString());
71-
super.onHeaders(headers);
72-
}
70+
@Override
71+
public void onHeaders(Metadata headers) {
72+
log.debug("gRPC headers: \n{}", headers.toString());
73+
super.onHeaders(headers);
74+
}
7375

74-
@Override
75-
public void onClose(Status status, Metadata trailers) {
76-
log.info("Interaction ends with status: {}", status.toString());
77-
log.info("Trailers: {}", trailers.toString());
78-
super.onClose(status, trailers);
79-
}
80-
}, headers);
76+
@Override
77+
public void onClose(Status status, Metadata trailers) {
78+
log.info("Interaction ends with status: {}", status.toString());
79+
log.info("Trailers: {}", trailers.toString());
80+
super.onClose(status, trailers);
81+
}
82+
}, headers);
8183
}
8284
};
8385
}

examples/local-grpc-client/src/main/java/net/devh/boot/grpc/examples/local/client/LogGrpcInterceptor.java

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717

1818
package net.devh.boot.grpc.examples.local.client;
1919

20+
import org.slf4j.Logger;
21+
import org.slf4j.LoggerFactory;
22+
2023
import io.grpc.CallOptions;
2124
import io.grpc.Channel;
2225
import io.grpc.ClientCall;
@@ -26,8 +29,6 @@
2629
import io.grpc.Metadata;
2730
import io.grpc.MethodDescriptor;
2831
import io.grpc.Status;
29-
import org.slf4j.Logger;
30-
import org.slf4j.LoggerFactory;
3132
import net.devh.boot.grpc.client.interceptor.GrpcGlobalClientInterceptor;
3233

3334
/**
@@ -60,26 +61,27 @@ public void sendMessage(ReqT message) {
6061

6162
@Override
6263
public void start(Listener<RespT> responseListener, Metadata headers) {
63-
super.start(new ForwardingClientCallListener.SimpleForwardingClientCallListener<RespT>(responseListener) {
64-
@Override
65-
public void onMessage(RespT message) {
66-
log.debug("Response message: \n{}", message.toString());
67-
super.onMessage(message);
68-
}
64+
super.start(
65+
new ForwardingClientCallListener.SimpleForwardingClientCallListener<RespT>(responseListener) {
66+
@Override
67+
public void onMessage(RespT message) {
68+
log.debug("Response message: \n{}", message.toString());
69+
super.onMessage(message);
70+
}
6971

70-
@Override
71-
public void onHeaders(Metadata headers) {
72-
log.debug("gRPC headers: \n{}", headers.toString());
73-
super.onHeaders(headers);
74-
}
72+
@Override
73+
public void onHeaders(Metadata headers) {
74+
log.debug("gRPC headers: \n{}", headers.toString());
75+
super.onHeaders(headers);
76+
}
7577

76-
@Override
77-
public void onClose(Status status, Metadata trailers) {
78-
log.info("Interaction ends with status: {}", status.toString());
79-
log.info("Trailers: {}", trailers.toString());
80-
super.onClose(status, trailers);
81-
}
82-
}, headers);
78+
@Override
79+
public void onClose(Status status, Metadata trailers) {
80+
log.info("Interaction ends with status: {}", status.toString());
81+
log.info("Trailers: {}", trailers.toString());
82+
super.onClose(status, trailers);
83+
}
84+
}, headers);
8385
}
8486
};
8587
}

0 commit comments

Comments
 (0)