Permalink
Browse files

Merge pull request #101 from pgelinas/improve-logging

Improve logging
  • Loading branch information...
2 parents c43c044 + cf7e617 commit eda22f0237cb9529f92415758ea2e488a4aac83d @helun committed Dec 12, 2012
@@ -129,9 +129,7 @@ public HttpResponse copy(String sourceUri, String destination) {
private HttpResponse executePutPost(HttpEntityEnclosingRequestBase request,
String content, boolean useBackend) {
try {
- if (LOG.isTraceEnabled()) {
- LOG.trace("Content: {}", content);
- }
+ LOG.trace("Content: {}", content);
StringEntity e = new StringEntity(content, "UTF-8");
e.setContentType("application/json");
request.setEntity(e);
@@ -156,11 +154,8 @@ private HttpResponse executeRequest(HttpRequestBase request, boolean useBackend)
} else {
rsp = client.execute((HttpHost)client.getParams().getParameter(ClientPNames.DEFAULT_HOST), request);
}
- if (LOG.isTraceEnabled()) {
- LOG.trace(String.format("%s %s %s %s", request.getMethod(),
- request.getURI(), rsp.getStatusLine().getStatusCode(),
- rsp.getStatusLine().getReasonPhrase()));
- }
+ LOG.trace("{} {} {} {}", new Object[] { request.getMethod(), request.getURI(),
+ rsp.getStatusLine().getStatusCode(), rsp.getStatusLine().getReasonPhrase() });
return AndroidHttpResponse.of(rsp, request);
} catch (Exception e) {
throw Exceptions.propagate(e);
@@ -113,9 +113,7 @@ protected void onSuccess() {
}
if(lastUpdateChangesFeed > lastUpdateView) {
- if (LOG.isDebugEnabled()) {
- LOG.debug("Finished, but still behind " + lastUpdateChangesFeed + " > " + lastUpdateView);
- }
+ LOG.debug("Finished, but still behind {} > {}", lastUpdateChangesFeed, lastUpdateView);
updateListItems();
}
@@ -860,6 +860,11 @@ public void setIgnoreNotFound(boolean ignoreNotFound) {
public boolean isIgnoreNotFound() {
return ignoreNotFound;
}
+
+ @Override
+ public String toString() {
+ return buildQuery();
+ }
public static class Keys {
@@ -121,6 +121,18 @@ public boolean 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 {
static final String VALUE_FIELD_NAME = "value";
@@ -184,6 +196,10 @@ private boolean isNull(JsonNode node) {
return node == null || node.isNull() || node.isMissingNode();
}
+ @Override
+ public String toString() {
+ return rowNode.toString();
+ }
}
}
@@ -122,9 +122,7 @@ public HttpResponse head(String uri) {
private HttpResponse executePutPost(HttpEntityEnclosingRequestBase request,
String content, boolean useBackend) {
try {
- if (LOG.isTraceEnabled()) {
- LOG.trace("Content: {}", content);
- }
+ LOG.trace("Content: {}", content);
StringEntity e = new StringEntity(content, "UTF-8");
e.setContentType("application/json");
request.setEntity(e);
@@ -151,11 +149,8 @@ private HttpResponse executeRequest(HttpUriRequest request, boolean useBackend)
} else {
rsp = client.execute((HttpHost)client.getParams().getParameter(ClientPNames.DEFAULT_HOST), request);
}
- if (LOG.isTraceEnabled()) {
- LOG.trace(String.format("%s %s %s %s", request.getMethod(),
- request.getURI(), rsp.getStatusLine().getStatusCode(),
- rsp.getStatusLine().getReasonPhrase()));
- }
+ LOG.trace("{} {} {} {}", new Object[] { request.getMethod(), request.getURI(),
+ rsp.getStatusLine().getStatusCode(), rsp.getStatusLine().getReasonPhrase() });
return StdHttpResponse.of(rsp, request);
} catch (Exception e) {
throw Exceptions.propagate(e);
@@ -180,10 +180,7 @@ public AttachmentInputStream getAttachment(final String id,
assertDocIdHasValue(id);
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));
}
@@ -194,10 +191,7 @@ public AttachmentInputStream getAttachment(String id, String attachmentId,
Assert.hasText(attachmentId, "attachmentId 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));
}
@@ -431,14 +425,17 @@ public String getDatabaseName() {
private <T> T executeQuery(final ViewQuery query,
ResponseCallback<T> rh) {
+ LOG.debug("Querying CouchDb view at {}.", query);
+ T result;
if (!query.isCacheOk()) {
- return query.hasMultipleKeys() ? restTemplate.postUncached(query.buildQuery(),
- query.getKeysAsJson(), rh) : restTemplate.getUncached(
- query.buildQuery(), rh);
+ result = query.hasMultipleKeys() ? restTemplate.postUncached(query.buildQuery(), query.getKeysAsJson(), rh)
+ : restTemplate.getUncached(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(),
- query.getKeysAsJson(), rh) : restTemplate.get(
- query.buildQuery(), rh);
+ LOG.debug("Answer from view query: {}.", result);
+ return result;
}
@Override
@@ -448,10 +445,8 @@ public String getDatabaseName() {
Assert.notNull(type, "type may not be null");
query.dbPath(dbURI.toString());
- if (LOG.isDebugEnabled()) {
- LOG.debug("startKey: {}", pr.getStartKey());
- LOG.debug("startDocId: {}", pr.getStartKeyDocId());
- }
+ LOG.debug("startKey: {}", pr.getStartKey());
+ LOG.debug("startDocId: {}", pr.getStartKeyDocId());
PageResponseHandler<T> ph = new PageResponseHandler<T>(pr, type, objectMapper, query.isIgnoreNotFound());
query = PageRequest.applyPagingParameters(query, pr);
@@ -81,12 +81,9 @@ public void run() {
*/
public String toJson(Object o) {
try {
- if (LOG.isDebugEnabled()) {
- String json = objectMapper.writeValueAsString(o);
- LOG.debug(json);
- return json;
- }
- return objectMapper.writeValueAsString(o);
+ String json = objectMapper.writeValueAsString(o);
+ LOG.debug(json);
+ return json;
} catch (Exception e) {
throw Exceptions.propagate(e);
}
@@ -291,7 +291,7 @@ private void initDesignDocInternal(int invocations) {
initDesignDocInternal(1);
}
}
- } else if (log.isDebugEnabled()){
+ } else {
log.debug("DesignDocument was unchanged. Database was not updated.");
}
}

0 comments on commit eda22f0

Please sign in to comment.