Skip to content

Commit

Permalink
[#noissue] Update agentInfo error log format
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Dec 6, 2023
1 parent 1fa9852 commit 8574f3c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -174,35 +174,48 @@ public void run() {
}

private boolean sendAgentInfo() {
AgentInfo agentInfo = null;
try {
AgentInfo agentInfo = agentInfoFactory.createAgentInfo();
agentInfo = agentInfoFactory.createAgentInfo();

logger.info("Sending AgentInfo {}", agentInfo);
logger.info("Sending AgentInfo={}", agentInfo);
ResponseFutureListener<ResponseMessage, Throwable> listener = new ResponseFutureListener<>();
dataSender.request(agentInfo, listener);
ResponseMessage responseMessage = listener.getResponseFuture().get(3000, TimeUnit.MILLISECONDS);
if (responseMessage == null) {
logger.warn("result not set");
if (agentInfo != null && agentInfo.getAgentInformation() != null) {
logger.warn("Failed to send agentInfo={}. result not set", agentInfo.getAgentInformation());
} else {
logger.warn("Failed to send agentInfo. result not set");
}
return false;
}
final ResultResponse result = messageConverter.toMessage(responseMessage);
if (!result.isSuccess()) {
logger.warn("request unsuccessful. Cause : {}", result.getMessage());
if (agentInfo != null && agentInfo.getAgentInformation() != null) {
logger.warn("Failed to send agentInfo={}. request unsuccessful, response={}", agentInfo.getAgentInformation(), result.getMessage());
} else {
logger.warn("Failed to send agentInfo. request unsuccessful, response={}", result.getMessage());
}
}
return result.isSuccess();
} catch (ExecutionException ex) {
logError(ex.getCause());
logError(agentInfo, ex.getCause());
} catch (InterruptedException ex) {
Thread.currentThread().interrupt();
logError(ex);
logError(agentInfo, ex);
} catch (TimeoutException ex) {
logError(ex);
logError(agentInfo, ex);
}
return false;
}

private void logError(Throwable cause) {
logger.warn("failed to send agent info", cause);
private void logError(AgentInfo agentInfo, Throwable cause) {
if (agentInfo != null && agentInfo.getAgentInformation() != null) {
logger.warn("Failed to send agentInfo={}", agentInfo.getAgentInformation(), cause);
} else {
logger.warn("Failed to send agentInfo", cause);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public String getAgentVersion() {

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("DefaultAgentInformation{");
final StringBuilder sb = new StringBuilder("{");
sb.append("agentId='").append(agentId).append('\'');
sb.append(", agentName='").append(agentName).append('\'');
sb.append(", applicationName='").append(applicationName).append('\'');
Expand Down

0 comments on commit 8574f3c

Please sign in to comment.