Skip to content

Commit

Permalink
Add logs in GitHubClient response. fix #1594
Browse files Browse the repository at this point in the history
  • Loading branch information
c3p0-maif committed Jan 11, 2023
1 parent 472adbb commit 087b8cb
Showing 1 changed file with 18 additions and 2 deletions.
20 changes: 18 additions & 2 deletions src/main/java/org/kohsuke/github/GitHubClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ public <T> GitHubResponse<T> sendRequest(GitHubRequest request, @CheckForNull Bo
logRequest(connectorRequest);
rateLimitChecker.checkRateLimit(this, request.rateLimitTarget());
connectorResponse = connector.send(connectorRequest);
logResponse(connectorResponse);
noteRateLimit(request.rateLimitTarget(), connectorResponse);
detectKnownErrors(connectorResponse, request, handler != null);
return createResponse(connectorResponse, handler);
Expand Down Expand Up @@ -520,8 +521,23 @@ private GitHubConnectorRequest prepareConnectorRequest(GitHubRequest request) th

private void logRequest(@Nonnull final GitHubConnectorRequest request) {
LOGGER.log(FINE,
() -> "GitHub API request [" + (getLogin() == null ? "anonymous" : getLogin()) + "]: "
+ request.method() + " " + request.url().toString());
() -> String.format("(%s) GitHub API request [%s]: %s",
Integer.toHexString(request.hashCode()),
(getLogin() == null ? "anonymous" : getLogin()),
(request.method() + " " + request.url().toString())));
}

private void logResponse(@Nonnull final GitHubConnectorResponse response) {
LOGGER.log(FINE, () -> {
try {
return String.format("(%s) GitHub API response [%s]: %s",
Integer.toHexString(response.request().hashCode()),
(getLogin() == null ? "anonymous" : getLogin()),
(response.statusCode() + " " + GitHubResponse.getBodyAsString(response)));
} catch (IOException e) {
throw new RuntimeException(e);
}
});
}

@Nonnull
Expand Down

0 comments on commit 087b8cb

Please sign in to comment.