Skip to content

Commit

Permalink
Only log debug messages when DEBUG is True (#453)
Browse files Browse the repository at this point in the history
According to the internal comments and other usage, this message should only be logged when DEBUG is True. The log entry can potentially contain sensitive data in the case where authentication tokens are part of a GET request and so it should be possible for the user of Volley to disable logging by setting DEBUG to False even in the case where the network request is "slow."

Fixes #452
  • Loading branch information
vorlon77 committed Jun 26, 2023
1 parent ce90b51 commit aa7ad9b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.android.volley.toolbox;

import static com.android.volley.toolbox.NetworkUtility.logSlowRequests;
import static com.android.volley.toolbox.NetworkUtility.logRequestSummary;

import android.os.SystemClock;
import androidx.annotation.NonNull;
Expand Down Expand Up @@ -213,9 +213,9 @@ private void onResponseRead(
OnRequestComplete callback,
List<Header> responseHeaders,
byte[] responseContents) {
// if the request is slow, log it.
// log request when debugging is enabled.
long requestLifetime = SystemClock.elapsedRealtime() - requestStartMs;
logSlowRequests(requestLifetime, request, responseContents, statusCode);
logRequestSummary(requestLifetime, request, responseContents, statusCode);

if (statusCode < 200 || statusCode > 299) {
onRequestFailed(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ public NetworkResponse performRequest(Request<?> request) throws VolleyError {
responseContents = new byte[0];
}

// if the request is slow, log it.
// log request when debugging is enabled.
long requestLifetime = SystemClock.elapsedRealtime() - requestStart;
NetworkUtility.logSlowRequests(
NetworkUtility.logRequestSummary(
requestLifetime, request, responseContents, statusCode);

if (statusCode < 200 || statusCode > 299) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@
* BasicAsyncNetwork}
*/
final class NetworkUtility {
private static final int SLOW_REQUEST_THRESHOLD_MS = 3000;

private NetworkUtility() {}

/** Logs requests that took over SLOW_REQUEST_THRESHOLD_MS to complete. */
static void logSlowRequests(
/** Logs a summary about the request when debug logging is enabled. */
static void logRequestSummary(
long requestLifetime, Request<?> request, byte[] responseContents, int statusCode) {
if (VolleyLog.DEBUG || requestLifetime > SLOW_REQUEST_THRESHOLD_MS) {
if (VolleyLog.DEBUG) {
VolleyLog.d(
"HTTP response for request=<%s> [lifetime=%d], [size=%s], "
+ "[rc=%d], [retryCount=%s]",
Expand Down

0 comments on commit aa7ad9b

Please sign in to comment.