Skip to content

Commit acdd07b

Browse files
authored
Introduce setDebugLoggingEnabled API (#549)
* include isDebugLoggingEnabled api to manually control the verbosity of http requests * preserve previous behavior * update note on logging
1 parent ec3b436 commit acdd07b

2 files changed

Lines changed: 31 additions & 2 deletions

File tree

mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/MapboxTelemetry.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public class MapboxTelemetry implements Callback, LocationEngineListener {
7474
protected CopyOnWriteArrayList<TelemetryListener> telemetryListeners;
7575
private Hashtable<String, Object> customTurnstileEvent = null;
7676
private int sessionIdRotationTime = TelemetryConstants.DEFAULT_SESSION_ID_ROTATION_HOURS;
77+
private boolean debugLoggingEnabled = false;
7778

7879
/**
7980
* Private constructor for configuring the single instance per app.
@@ -167,6 +168,25 @@ public void setSessionIdRotationTime(@IntRange(from = 1, to = 24) int sessionIdR
167168
this.sessionIdRotationTime = sessionIdRotationTime; // in hours
168169
}
169170

171+
// For internal use only
172+
// This is an experimental API. Experimental APIs are quickly evolving and
173+
// might change or be removed in minor versions.
174+
@Experimental
175+
public boolean isDebugLoggingEnabled() {
176+
return debugLoggingEnabled;
177+
}
178+
179+
// For internal use only
180+
// This is an experimental API. Experimental APIs are quickly evolving and
181+
// might change or be removed in minor versions.
182+
@Experimental
183+
public void setDebugLoggingEnabled(boolean debugLoggingEnabled) {
184+
this.debugLoggingEnabled = debugLoggingEnabled;
185+
if (this.client != null) {
186+
this.client.setDebugLoggingEnabled(debugLoggingEnabled);
187+
}
188+
}
189+
170190
/**
171191
* Checks that TelemetryService has been configured by developer
172192
*/

mapbox/libandroid-telemetry/src/main/java/com/mapbox/services/android/telemetry/http/TelemetryClient.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class TelemetryClient {
3737
private String eventsCnEndpoint = MapboxEvent.MAPBOX_EVENTS_CN_BASE_URL;
3838
private boolean stagingEnvironment = false;
3939
private boolean enableCnEndpoint = false;
40+
private boolean debugLoggingEnabled = false;
4041
private OkHttpClient client;
4142

4243
public TelemetryClient(String accessToken) {
@@ -88,6 +89,14 @@ public void setEnableCnEndpoint() {
8889
this.enableCnEndpoint = true;
8990
}
9091

92+
public boolean isDebugLoggingEnabled() {
93+
return debugLoggingEnabled;
94+
}
95+
96+
public void setDebugLoggingEnabled(boolean debugLoggingEnabled) {
97+
this.debugLoggingEnabled = debugLoggingEnabled;
98+
}
99+
91100
/**
92101
* Based on http://square.github.io/okhttp/3.x/okhttp/okhttp3/CertificatePinner.html
93102
*
@@ -218,8 +227,8 @@ private void sendEventsWrapped(Vector<Hashtable<String, Object>> events, Callbac
218227
RequestBody body = RequestBody.create(JSON, payload);
219228
String url = getEventsEndpoint() + "/events/v2?access_token=" + getAccessToken();
220229

221-
// Extra debug in staging mode
222-
if (isStagingEnvironment()) {
230+
// Extra debug if manually enabled or if in staging mode
231+
if (isDebugLoggingEnabled() || isStagingEnvironment()) {
223232
Log.d(LOG_TAG, String.format("Sending POST to %s with %d event(s) (user agent: %s) with payload: %s",
224233
url, events.size(), getUserAgent(), payload));
225234
}

0 commit comments

Comments
 (0)