diff options
author | Samuel Tardieu <sam@rfc1149.net> | 2011-10-01 10:49:57 +0200 |
---|---|---|
committer | Samuel Tardieu <sam@rfc1149.net> | 2011-10-01 13:05:16 +0200 |
commit | 88906d9e2f7d343dd3b8ec522add091626f727a8 (patch) | |
tree | 74afaaa43d228bf2a33465222d9855f0cbfe7435 /main/src | |
parent | 96892b9e7bdc155b4cbae829d9d888ea80750214 (diff) | |
download | cgeo-88906d9e2f7d343dd3b8ec522add091626f727a8.zip cgeo-88906d9e2f7d343dd3b8ec522add091626f727a8.tar.gz cgeo-88906d9e2f7d343dd3b8ec522add091626f727a8.tar.bz2 |
Display HTTP response code and timing information in log
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/cgeo/geocaching/cgBase.java | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java index d9ba8d2..b7be150 100644 --- a/main/src/cgeo/geocaching/cgBase.java +++ b/main/src/cgeo/geocaching/cgBase.java @@ -3266,18 +3266,27 @@ public class cgBase { return doRequest(request); } + static private String formatTimeSpan(final long before) { + return String.format(" (%d ms)", System.currentTimeMillis() - before); + } + static public HttpResponse doRequest(final HttpRequestBase request) { - Log.d(cgSettings.tag, "request: " + request.getMethod() + " " + hidePassword(request.getURI().toString())); + final String method = request.getMethod(); + Log.d(cgSettings.tag, method + " " + hidePassword(request.getURI().toString())); final HttpClient client = getHttpClient(); for (int i = 0; i <= NB_DOWNLOAD_RETRIES; i++) { + final long before = System.currentTimeMillis(); try { - return client.execute(request); + final HttpResponse response = client.execute(request); + Log.d(cgSettings.tag, method + " request returned " + response.getStatusLine().getStatusCode() + formatTimeSpan(before)); + return response; } catch (IOException e) { + final String timeSpan = formatTimeSpan(before); if (i == NB_DOWNLOAD_RETRIES) { - Log.e(cgSettings.tag, "cgeoBase.request", e); + Log.e(cgSettings.tag, "cgeoBase.doRequest: failure" + timeSpan, e); } else { - Log.e(cgSettings.tag, "cgeoBase.request: failed to download data (" + e.getMessage() + "), retrying"); + Log.e(cgSettings.tag, "cgeoBase.doRequest: failed to download data (" + e.getMessage() + "), retrying" + timeSpan); } } } |