Skip to content

Commit

Permalink
[fix][sdk] Rpc use service logger.
Browse files Browse the repository at this point in the history
  • Loading branch information
JYcz authored and ketor committed Mar 7, 2024
1 parent 7b9a06a commit b10daa2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.fasterxml.jackson.databind.module.SimpleModule;
import com.google.common.base.CaseFormat;
import io.dingodb.sdk.common.utils.ByteArrayUtils;
import io.dingodb.sdk.common.utils.StackTraces;
import io.dingodb.sdk.service.entity.Message;
Expand All @@ -14,6 +15,8 @@

import java.io.IOException;

import static com.google.common.base.CaseFormat.LOWER_CAMEL;
import static com.google.common.base.CaseFormat.UPPER_CAMEL;
import static io.dingodb.sdk.common.utils.StackTraces.CURRENT_STACK;

public class JsonMessageUtils {
Expand Down Expand Up @@ -66,7 +69,7 @@ public static String toJson(
.trace(trace)
.options(options)
.method(method)
.step(StackTraces.methodName(CURRENT_STACK + 1))
.step(LOWER_CAMEL.to(UPPER_CAMEL, StackTraces.methodName(CURRENT_STACK + 1)))
.request(request)
.response(response)
.build()
Expand All @@ -87,7 +90,7 @@ public static String toJson(
.trace(trace)
.options(options)
.method(method)
.step(StackTraces.methodName(CURRENT_STACK + 1))
.step(LOWER_CAMEL.to(UPPER_CAMEL, StackTraces.methodName(CURRENT_STACK + 1)))
.remote(remote)
.request(request)
.response(response)
Expand All @@ -111,7 +114,7 @@ public static String toJson(
.trace(trace)
.options(options)
.method(method)
.step(StackTraces.methodName(CURRENT_STACK + 1))
.step(LOWER_CAMEL.to(UPPER_CAMEL, StackTraces.methodName(CURRENT_STACK + 1)))
.remote(remote)
.request(request)
.response(response)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public RES call(
@Override
public void before(REQ req, CallOptions options, long trace) {
if (Before.log.isDebugEnabled() && logger.isDebugEnabled()) {
Before.log.debug(
logger.debug(
toJson(method.getFullMethodName(), trace, req, null, options)
);
}
Expand All @@ -176,7 +176,7 @@ public void before(REQ req, CallOptions options, long trace) {
@Override
public void rBefore(REQ req, CallOptions options, String remote, long trace) {
if (RBefore.log.isDebugEnabled() && logger.isDebugEnabled()) {
RBefore.log.debug(
logger.debug(
toJson(remote, method.getFullMethodName(), trace, req, null, options)
);
}
Expand All @@ -188,7 +188,7 @@ public void rBefore(REQ req, CallOptions options, String remote, long trace) {
@Override
public void after(REQ req, RES res, CallOptions options, String remote, long trace) {
if (After.log.isDebugEnabled() && logger.isDebugEnabled()) {
After.log.debug(
logger.debug(
toJson(remote, method.getFullMethodName(), trace, req, res, options)
);
}
Expand All @@ -200,7 +200,7 @@ public void after(REQ req, RES res, CallOptions options, String remote, long tra
@Override
public void rAfter(REQ req, RES res, CallOptions options, String remote, long trace) {
if (RAfter.log.isDebugEnabled() && logger.isDebugEnabled()) {
RAfter.log.debug(
logger.debug(
toJson(remote, method.getFullMethodName(), trace, req, res, options)
);
}
Expand All @@ -212,7 +212,7 @@ public void rAfter(REQ req, RES res, CallOptions options, String remote, long tr
@Override
public void rError(REQ req, CallOptions options, String remote, long trace, String statusMessage) {
if (RError.log.isDebugEnabled() && logger.isDebugEnabled()) {
RError.log.debug(
logger.debug(
toJson(statusMessage, remote, method.getFullMethodName(), trace, req, null, options, null)
);
}
Expand All @@ -233,7 +233,7 @@ public ErrorCodeUtils.Strategy onErrStrategy(
long trace
) {
if (ServiceCallCycles.OnErrRes.log.isDebugEnabled() && logger.isDebugEnabled()) {
OnErrRes.log.debug(
logger.debug(
"Service call [{}:{}] error on [{}], trace [{}], retry: {}, remain: {}, req: {}, res: {}, options: {}",
remote, method.getFullMethodName(), System.currentTimeMillis(), trace, retry, remain, req, res, options
);
Expand All @@ -244,7 +244,7 @@ public ErrorCodeUtils.Strategy onErrStrategy(
strategy = onErrRes.onErrStrategy(strategy, retry, remain, req, res, options, remote, trace);
}
if (before != strategy && ServiceCallCycles.OnErrRes.log.isDebugEnabled() && logger.isDebugEnabled()) {
OnErrRes.log.debug(
logger.debug(
"Service call [{}:{}] error on [{}], trace [{}], before strategy [{}], change to [{}]",
remote, method.getFullMethodName(), System.currentTimeMillis(), trace, before, strategy
);
Expand All @@ -255,7 +255,7 @@ public ErrorCodeUtils.Strategy onErrStrategy(
@Override
public void onException(REQ req, Exception ex, CallOptions options, String remote, long trace) {
if (OnException.log.isDebugEnabled() && logger.isDebugEnabled()) {
OnException.log.debug(
logger.debug(
toJson(null, remote, method.getFullMethodName(), trace, req, null, options, ex)
);
}
Expand All @@ -267,7 +267,7 @@ public void onException(REQ req, Exception ex, CallOptions options, String remot
@Override
public void onRetry(REQ req, RES res, CallOptions options, String remote, long trace) {
if (OnRetry.log.isDebugEnabled() && logger.isDebugEnabled()) {
OnRetry.log.debug(
logger.debug(
toJson(remote, method.getFullMethodName(), trace, req, res, options)
);
}
Expand All @@ -279,7 +279,7 @@ public void onRetry(REQ req, RES res, CallOptions options, String remote, long t
@Override
public void onFailed(REQ req, RES res, CallOptions options, String remote, long trace) {
if (OnFailed.log.isDebugEnabled() && logger.isDebugEnabled()) {
OnFailed.log.debug(
logger.debug(
toJson(remote, method.getFullMethodName(), trace, req, res, options)
);
}
Expand All @@ -291,7 +291,7 @@ public void onFailed(REQ req, RES res, CallOptions options, String remote, long
@Override
public void onIgnore(REQ req, RES res, CallOptions options, String remote, long trace) {
if (OnIgnore.log.isDebugEnabled() && logger.isDebugEnabled()) {
OnIgnore.log.debug(
logger.debug(
toJson(remote, method.getFullMethodName(), trace, req, res, options)

);
Expand All @@ -304,7 +304,7 @@ public void onIgnore(REQ req, RES res, CallOptions options, String remote, long
@Override
public void onRefresh(REQ req, RES res, CallOptions options, String remote, long trace) {
if (OnRefresh.log.isDebugEnabled() && logger.isDebugEnabled()) {
OnRefresh.log.debug(
logger.debug(
toJson(remote, method.getFullMethodName(), trace, req, res, options)
);
}
Expand All @@ -316,7 +316,9 @@ public void onRefresh(REQ req, RES res, CallOptions options, String remote, long
@Override
public void onNonConnection(REQ req, CallOptions options, long trace) {
if (OnNonConnection.log.isDebugEnabled() && logger.isDebugEnabled()) {
toJson(method.getFullMethodName(), trace, req, null, options);
logger.debug(
toJson(method.getFullMethodName(), trace, req, null, options)
);
}
for (ServiceCallCycle.OnNonConnection<REQ, RES> onNonConnection : onNonConnection.list) {
onNonConnection.onNonConnection(req, options, trace);
Expand All @@ -326,7 +328,7 @@ public void onNonConnection(REQ req, CallOptions options, long trace) {
@Override
public void onThrow(REQ req, ExhaustedRetryException ex, CallOptions options, long trace) {
if (ServiceCallCycles.OnThrow.log.isDebugEnabled() && logger.isDebugEnabled()) {
ServiceCallCycles.OnThrow.log.debug(
logger.debug(
toJson(null, null, method.getFullMethodName(), trace, req, null, options, ex)
);
}
Expand Down

0 comments on commit b10daa2

Please sign in to comment.