summaryrefslogtreecommitdiff
path: root/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
diff options
context:
space:
mode:
authorTobrun <tobrun.van.nuland@gmail.com>2017-12-12 09:26:47 +0100
committerTobrun <tobrun@mapbox.com>2017-12-12 17:25:27 +0100
commit7c06eda515ded2728594377610f75f309c22e913 (patch)
treef49c3906a764c8f8b7bd2502813e24cf1a9e3bfc /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
parentcf026d1932ca380a799dd4263e02dce67d22806b (diff)
downloadqtlocation-mapboxgl-7c06eda515ded2728594377610f75f309c22e913.tar.gz
[android] - allow configurable http logging
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java')
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java36
1 files changed, 23 insertions, 13 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
index 9c7fe4ee63..8463814794 100644
--- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
+++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/http/HTTPRequest.java
@@ -33,6 +33,7 @@ import timber.log.Timber;
class HTTPRequest implements Callback {
private static OkHttpClient mClient = new OkHttpClient.Builder().dispatcher(getDispatcher()).build();
+ private static boolean logEnabled = true;
private String USER_AGENT_STRING = null;
private static final int CONNECTION_ERROR = 0;
@@ -118,12 +119,15 @@ class HTTPRequest implements Callback {
@Override
public void onResponse(Call call, Response response) throws IOException {
- if (response.isSuccessful()) {
- Timber.v("[HTTP] Request was successful (code = %s).", response.code());
- } else {
- // We don't want to call this unsuccessful because a 304 isn't really an error
- String message = !TextUtils.isEmpty(response.message()) ? response.message() : "No additional information";
- Timber.d("[HTTP] Request with response code = %s: %s", response.code(), message);
+
+ if (logEnabled) {
+ if (response.isSuccessful()) {
+ Timber.v("[HTTP] Request was successful (code = %s).", response.code());
+ } else {
+ // We don't want to call this unsuccessful because a 304 isn't really an error
+ String message = !TextUtils.isEmpty(response.message()) ? response.message() : "No additional information";
+ Timber.d("[HTTP] Request with response code = %s: %s", response.code(), message);
+ }
}
byte[] body;
@@ -167,13 +171,15 @@ class HTTPRequest implements Callback {
String errorMessage = e.getMessage() != null ? e.getMessage() : "Error processing the request";
- if (type == TEMPORARY_ERROR) {
- Timber.d("Request failed due to a temporary error: %s", errorMessage);
- } else if (type == CONNECTION_ERROR) {
- Timber.i("Request failed due to a connection error: %s", errorMessage);
- } else {
- // PERMANENT_ERROR
- Timber.w("Request failed due to a permanent error: %s", errorMessage);
+ if (logEnabled) {
+ if (type == TEMPORARY_ERROR) {
+ Timber.d("Request failed due to a temporary error: %s", errorMessage);
+ } else if (type == CONNECTION_ERROR) {
+ Timber.i("Request failed due to a connection error: %s", errorMessage);
+ } else {
+ // PERMANENT_ERROR
+ Timber.w("Request failed due to a permanent error: %s", errorMessage);
+ }
}
mLock.lock();
@@ -207,4 +213,8 @@ class HTTPRequest implements Callback {
return "";
}
}
+
+ static void enableLog(boolean enabled) {
+ logEnabled = enabled;
+ }
}