Skip to content

Commit eb7bb1e

Browse files
authored
Disable verbose logging in transport-runtime. (#3648)
* Disable verbose logging in transport-runtime. fixes #3441 * Address review comments.
1 parent 2cbed1d commit eb7bb1e

File tree

2 files changed

+33
-12
lines changed
  • transport
    • transport-backend-cct/src/main/java/com/google/android/datatransport/cct
    • transport-runtime/src/main/java/com/google/android/datatransport/runtime/logging

2 files changed

+33
-12
lines changed

transport/transport-backend-cct/src/main/java/com/google/android/datatransport/cct/CctTransportBackend.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ private BatchedLogRequest getRequestBody(BackendRequest backendRequest) {
283283

284284
private HttpResponse doSend(HttpRequest request) throws IOException {
285285

286-
Logging.d(LOG_TAG, "Making request to: %s", request.url);
286+
Logging.i(LOG_TAG, "Making request to: %s", request.url);
287287
HttpURLConnection connection = (HttpURLConnection) request.url.openConnection();
288288
connection.setConnectTimeout(CONNECTION_TIME_OUT);
289289
connection.setReadTimeout(readTimeout);
@@ -315,9 +315,9 @@ private HttpResponse doSend(HttpRequest request) throws IOException {
315315
}
316316

317317
int responseCode = connection.getResponseCode();
318-
Logging.i(LOG_TAG, "Status Code: " + responseCode);
319-
Logging.i(LOG_TAG, "Content-Type: " + connection.getHeaderField("Content-Type"));
320-
Logging.i(LOG_TAG, "Content-Encoding: " + connection.getHeaderField("Content-Encoding"));
318+
Logging.i(LOG_TAG, "Status Code: %d", responseCode);
319+
Logging.d(LOG_TAG, "Content-Type: %s", connection.getHeaderField("Content-Type"));
320+
Logging.d(LOG_TAG, "Content-Encoding: %s", connection.getHeaderField("Content-Encoding"));
321321

322322
if (responseCode == 302 || responseCode == 301 || responseCode == 307) {
323323
String redirect = connection.getHeaderField("Location");

transport/transport-runtime/src/main/java/com/google/android/datatransport/runtime/logging/Logging.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,51 @@ private static String getTag(String tag) {
2424
}
2525

2626
public static void d(String tag, String message) {
27-
Log.d(getTag(tag), message);
27+
tag = getTag(tag);
28+
if (Log.isLoggable(tag, Log.DEBUG)) {
29+
Log.d(tag, message);
30+
}
2831
}
2932

3033
public static void d(String tag, String message, Object arg1) {
31-
Log.d(getTag(tag), String.format(message, arg1));
34+
tag = getTag(tag);
35+
if (Log.isLoggable(tag, Log.DEBUG)) {
36+
Log.d(tag, String.format(message, arg1));
37+
}
3238
}
3339

3440
public static void d(String tag, String message, Object arg1, Object arg2) {
35-
Log.d(getTag(tag), String.format(message, arg1, arg2));
41+
tag = getTag(tag);
42+
if (Log.isLoggable(tag, Log.DEBUG)) {
43+
Log.d(tag, String.format(message, arg1, arg2));
44+
}
3645
}
3746

3847
public static void d(String tag, String message, Object... args) {
39-
Log.d(getTag(tag), String.format(message, args));
48+
tag = getTag(tag);
49+
if (Log.isLoggable(tag, Log.DEBUG)) {
50+
Log.d(tag, String.format(message, args));
51+
}
4052
}
4153

42-
public static void i(String tag, String message) {
43-
Log.i(getTag(tag), message);
54+
public static void i(String tag, String message, Object arg1) {
55+
tag = getTag(tag);
56+
if (Log.isLoggable(tag, Log.INFO)) {
57+
Log.i(tag, String.format(message, arg1));
58+
}
4459
}
4560

4661
public static void e(String tag, String message, Throwable e) {
47-
Log.e(getTag(tag), message, e);
62+
tag = getTag(tag);
63+
if (Log.isLoggable(tag, Log.ERROR)) {
64+
Log.e(tag, message, e);
65+
}
4866
}
4967

5068
public static void w(String tag, String message, Object arg1) {
51-
Log.w(getTag(tag), String.format(message, arg1));
69+
tag = getTag(tag);
70+
if (Log.isLoggable(tag, Log.WARN)) {
71+
Log.w(tag, String.format(message, arg1));
72+
}
5273
}
5374
}

0 commit comments

Comments
 (0)