Skip to content
This repository has been archived by the owner on Sep 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #19 from libgraviton/feature/remove-log-message-tr…
Browse files Browse the repository at this point in the history
…uncation

remove log message truncation
  • Loading branch information
q-src authored May 10, 2017
2 parents bad0255 + 00ad72b commit 02475c7
Showing 1 changed file with 5 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,36 +76,28 @@ public Response execute(Request request) throws CommunicationException {
}

protected void logBody(Request request) {
int maxBodySize = 1000;
String truncatePostfix = "... [body too big to display in its complete beauty]";

if (request.getBody() != null) {
logStandardRequest(request, maxBodySize, truncatePostfix);
logStandardRequest(request);
}

if (request.getParts() != null && request.getParts().size() > 0) {
logMultipartRequest(request, maxBodySize, truncatePostfix);
logMultipartRequest(request);
}
}

private void logStandardRequest(Request request, int maxBodySize, String truncatePostfix) {
private void logStandardRequest(Request request) {
String body = request.getBody();
body = body.length() <= maxBodySize
? body
: body.substring(0, maxBodySize) + truncatePostfix;
LOG.debug("with request body '" + body + "'");
}

private void logMultipartRequest(Request request, int maxBodySize, String truncatePostfix) {
private void logMultipartRequest(Request request) {
StringBuilder builder = new StringBuilder();
for (Part part: request.getParts()) {
byte[] body = part.getBody();
String loggablePart = "Part{" +
"formName='" + part.getFormName() + '\'' +
", body='" +
(body.length <= maxBodySize
? new String(body)
: new String(Arrays.copyOfRange(body, 0, maxBodySize)) + truncatePostfix) +
new String(body) +
'\'' +
"}";
builder.append(loggablePart).append("\n");
Expand Down

0 comments on commit 02475c7

Please sign in to comment.