Skip to content

Commit

Permalink
Merge pull request #101 from pgelinas/improve-logging
Browse files Browse the repository at this point in the history
Improve logging
  • Loading branch information
Henrik Lundgren committed Dec 12, 2012
2 parents c43c044 + cf7e617 commit eda22f0
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 44 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ public HttpResponse copy(String sourceUri, String destination) {
private HttpResponse executePutPost(HttpEntityEnclosingRequestBase request, private HttpResponse executePutPost(HttpEntityEnclosingRequestBase request,
String content, boolean useBackend) { String content, boolean useBackend) {
try { try {
if (LOG.isTraceEnabled()) { LOG.trace("Content: {}", content);
LOG.trace("Content: {}", content);
}
StringEntity e = new StringEntity(content, "UTF-8"); StringEntity e = new StringEntity(content, "UTF-8");
e.setContentType("application/json"); e.setContentType("application/json");
request.setEntity(e); request.setEntity(e);
Expand All @@ -156,11 +154,8 @@ private HttpResponse executeRequest(HttpRequestBase request, boolean useBackend)
} else { } else {
rsp = client.execute((HttpHost)client.getParams().getParameter(ClientPNames.DEFAULT_HOST), request); rsp = client.execute((HttpHost)client.getParams().getParameter(ClientPNames.DEFAULT_HOST), request);
} }
if (LOG.isTraceEnabled()) { LOG.trace("{} {} {} {}", new Object[] { request.getMethod(), request.getURI(),
LOG.trace(String.format("%s %s %s %s", request.getMethod(), rsp.getStatusLine().getStatusCode(), rsp.getStatusLine().getReasonPhrase() });
request.getURI(), rsp.getStatusLine().getStatusCode(),
rsp.getStatusLine().getReasonPhrase()));
}
return AndroidHttpResponse.of(rsp, request); return AndroidHttpResponse.of(rsp, request);
} catch (Exception e) { } catch (Exception e) {
throw Exceptions.propagate(e); throw Exceptions.propagate(e);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -113,9 +113,7 @@ protected void onSuccess() {
} }


if(lastUpdateChangesFeed > lastUpdateView) { if(lastUpdateChangesFeed > lastUpdateView) {
if (LOG.isDebugEnabled()) { LOG.debug("Finished, but still behind {} > {}", lastUpdateChangesFeed, lastUpdateView);
LOG.debug("Finished, but still behind " + lastUpdateChangesFeed + " > " + lastUpdateView);
}
updateListItems(); updateListItems();
} }


Expand Down
5 changes: 5 additions & 0 deletions org.ektorp/src/main/java/org/ektorp/ViewQuery.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -860,6 +860,11 @@ public void setIgnoreNotFound(boolean ignoreNotFound) {
public boolean isIgnoreNotFound() { public boolean isIgnoreNotFound() {
return ignoreNotFound; return ignoreNotFound;
} }

@Override
public String toString() {
return buildQuery();
}


public static class Keys { public static class Keys {


Expand Down
16 changes: 16 additions & 0 deletions org.ektorp/src/main/java/org/ektorp/ViewResult.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -121,6 +121,18 @@ public boolean isEmpty() {
return rows.isEmpty(); return rows.isEmpty();
} }


@Override
public String toString() {
StringBuilder builder = new StringBuilder("{\n\"total_rows\":");
builder.append(totalRows);
builder.append(",\n\"offset\":");
builder.append(offset);
builder.append(",\n\"rows\":");
builder.append(rows.toString());
builder.append("\n}");
return builder.toString();
}

public static class Row { public static class Row {


static final String VALUE_FIELD_NAME = "value"; static final String VALUE_FIELD_NAME = "value";
Expand Down Expand Up @@ -184,6 +196,10 @@ private boolean isNull(JsonNode node) {
return node == null || node.isNull() || node.isMissingNode(); return node == null || node.isNull() || node.isMissingNode();
} }


@Override
public String toString() {
return rowNode.toString();
}
} }


} }
11 changes: 3 additions & 8 deletions org.ektorp/src/main/java/org/ektorp/http/StdHttpClient.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ public HttpResponse head(String uri) {
private HttpResponse executePutPost(HttpEntityEnclosingRequestBase request, private HttpResponse executePutPost(HttpEntityEnclosingRequestBase request,
String content, boolean useBackend) { String content, boolean useBackend) {
try { try {
if (LOG.isTraceEnabled()) { LOG.trace("Content: {}", content);
LOG.trace("Content: {}", content);
}
StringEntity e = new StringEntity(content, "UTF-8"); StringEntity e = new StringEntity(content, "UTF-8");
e.setContentType("application/json"); e.setContentType("application/json");
request.setEntity(e); request.setEntity(e);
Expand All @@ -151,11 +149,8 @@ private HttpResponse executeRequest(HttpUriRequest request, boolean useBackend)
} else { } else {
rsp = client.execute((HttpHost)client.getParams().getParameter(ClientPNames.DEFAULT_HOST), request); rsp = client.execute((HttpHost)client.getParams().getParameter(ClientPNames.DEFAULT_HOST), request);
} }
if (LOG.isTraceEnabled()) { LOG.trace("{} {} {} {}", new Object[] { request.getMethod(), request.getURI(),
LOG.trace(String.format("%s %s %s %s", request.getMethod(), rsp.getStatusLine().getStatusCode(), rsp.getStatusLine().getReasonPhrase() });
request.getURI(), rsp.getStatusLine().getStatusCode(),
rsp.getStatusLine().getReasonPhrase()));
}
return StdHttpResponse.of(rsp, request); return StdHttpResponse.of(rsp, request);
} catch (Exception e) { } catch (Exception e) {
throw Exceptions.propagate(e); throw Exceptions.propagate(e);
Expand Down
31 changes: 13 additions & 18 deletions org.ektorp/src/main/java/org/ektorp/impl/StdCouchDbConnector.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ public AttachmentInputStream getAttachment(final String id,
assertDocIdHasValue(id); assertDocIdHasValue(id);
Assert.hasText(attachmentId, "attachmentId may not be null or empty"); Assert.hasText(attachmentId, "attachmentId may not be null or empty");


if (LOG.isTraceEnabled()) { LOG.trace("fetching attachment for doc: {} attachmentId: {}", id, attachmentId);
LOG.trace("fetching attachment for doc: {} attachmentId: {}", id,
attachmentId);
}
return getAttachment(attachmentId, dbURI.append(id).append(attachmentId)); return getAttachment(attachmentId, dbURI.append(id).append(attachmentId));
} }


Expand All @@ -194,10 +191,7 @@ public AttachmentInputStream getAttachment(String id, String attachmentId,
Assert.hasText(attachmentId, "attachmentId may not be null or empty"); Assert.hasText(attachmentId, "attachmentId may not be null or empty");
Assert.hasText(revision, "revision may not be null or empty"); Assert.hasText(revision, "revision may not be null or empty");


if (LOG.isTraceEnabled()) { LOG.trace("fetching attachment for doc: {} attachmentId: {}", id, attachmentId);
LOG.trace("fetching attachment for doc: {} attachmentId: {}", id,
attachmentId);
}
return getAttachment(attachmentId, dbURI.append(id).append(attachmentId).param("rev", revision)); return getAttachment(attachmentId, dbURI.append(id).append(attachmentId).param("rev", revision));
} }


Expand Down Expand Up @@ -431,14 +425,17 @@ public <T> List<T> queryView(final ViewQuery query, final Class<T> type) {


private <T> T executeQuery(final ViewQuery query, private <T> T executeQuery(final ViewQuery query,
ResponseCallback<T> rh) { ResponseCallback<T> rh) {
LOG.debug("Querying CouchDb view at {}.", query);
T result;
if (!query.isCacheOk()) { if (!query.isCacheOk()) {
return query.hasMultipleKeys() ? restTemplate.postUncached(query.buildQuery(), result = query.hasMultipleKeys() ? restTemplate.postUncached(query.buildQuery(), query.getKeysAsJson(), rh)
query.getKeysAsJson(), rh) : restTemplate.getUncached( : restTemplate.getUncached(query.buildQuery(), rh);
query.buildQuery(), rh); } else {
result = query.hasMultipleKeys() ? restTemplate.post(query.buildQuery(), query.getKeysAsJson(), rh)
: restTemplate.get(query.buildQuery(), rh);
} }
return query.hasMultipleKeys() ? restTemplate.post(query.buildQuery(), LOG.debug("Answer from view query: {}.", result);
query.getKeysAsJson(), rh) : restTemplate.get( return result;
query.buildQuery(), rh);
} }


@Override @Override
Expand All @@ -448,10 +445,8 @@ public <T> Page<T> queryForPage(ViewQuery query, PageRequest pr, Class<T> type)
Assert.notNull(type, "type may not be null"); Assert.notNull(type, "type may not be null");


query.dbPath(dbURI.toString()); query.dbPath(dbURI.toString());
if (LOG.isDebugEnabled()) { LOG.debug("startKey: {}", pr.getStartKey());
LOG.debug("startKey: {}", pr.getStartKey()); LOG.debug("startDocId: {}", pr.getStartKeyDocId());
LOG.debug("startDocId: {}", pr.getStartKeyDocId());
}
PageResponseHandler<T> ph = new PageResponseHandler<T>(pr, type, objectMapper, query.isIgnoreNotFound()); PageResponseHandler<T> ph = new PageResponseHandler<T>(pr, type, objectMapper, query.isIgnoreNotFound());
query = PageRequest.applyPagingParameters(query, pr); query = PageRequest.applyPagingParameters(query, pr);


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -81,12 +81,9 @@ public void run() {
*/ */
public String toJson(Object o) { public String toJson(Object o) {
try { try {
if (LOG.isDebugEnabled()) { String json = objectMapper.writeValueAsString(o);
String json = objectMapper.writeValueAsString(o); LOG.debug(json);
LOG.debug(json); return json;
return json;
}
return objectMapper.writeValueAsString(o);
} catch (Exception e) { } catch (Exception e) {
throw Exceptions.propagate(e); throw Exceptions.propagate(e);
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ private void initDesignDocInternal(int invocations) {
initDesignDocInternal(1); initDesignDocInternal(1);
} }
} }
} else if (log.isDebugEnabled()){ } else {
log.debug("DesignDocument was unchanged. Database was not updated."); log.debug("DesignDocument was unchanged. Database was not updated.");
} }
} }
Expand Down

0 comments on commit eda22f0

Please sign in to comment.