forked from square/retrofit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request square#328 from square/jw/dont-mock-me
Promote Android logging to a class which knows about chunking.
- Loading branch information
Showing
3 changed files
with
26 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -107,7 +107,6 @@ | |
* @author Jake Wharton ([email protected]) | ||
*/ | ||
public class RestAdapter { | ||
private static final int LOG_CHUNK_SIZE = 4000; | ||
static final String THREAD_PREFIX = "Retrofit-"; | ||
static final String IDLE_THREAD_NAME = THREAD_PREFIX + "Idle"; | ||
|
||
|
@@ -396,11 +395,7 @@ private Request logAndReplaceRequest(Request request) throws IOException { | |
byte[] bodyBytes = ((TypedByteArray) body).getBytes(); | ||
bodySize = bodyBytes.length; | ||
String bodyCharset = MimeUtil.parseCharset(bodyMime); | ||
String bodyString = new String(bodyBytes, bodyCharset); | ||
for (int i = 0, len = bodyString.length(); i < len; i += LOG_CHUNK_SIZE) { | ||
int end = Math.min(len, i + LOG_CHUNK_SIZE); | ||
log.log(bodyString.substring(i, end)); | ||
} | ||
log.log(new String(bodyBytes, bodyCharset)); | ||
} | ||
} | ||
|
||
|
@@ -440,11 +435,7 @@ private Response logAndReplaceResponse(String url, Response response, long elaps | |
bodySize = bodyBytes.length; | ||
String bodyMime = body.mimeType(); | ||
String bodyCharset = MimeUtil.parseCharset(bodyMime); | ||
String bodyString = new String(bodyBytes, bodyCharset); | ||
for (int i = 0, len = bodyString.length(); i < len; i += LOG_CHUNK_SIZE) { | ||
int end = Math.min(len, i + LOG_CHUNK_SIZE); | ||
log.log(bodyString.substring(i, end)); | ||
} | ||
log.log(new String(bodyBytes, bodyCharset)); | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package retrofit.android; | ||
|
||
import android.util.Log; | ||
import retrofit.RestAdapter; | ||
|
||
/** A {@link RestAdapter.Log logger} for Android. */ | ||
public class AndroidLog implements RestAdapter.Log { | ||
private static final int LOG_CHUNK_SIZE = 4000; | ||
|
||
private final String tag; | ||
|
||
public AndroidLog(String tag) { | ||
this.tag = tag; | ||
} | ||
|
||
@Override public void log(String message) { | ||
for (int i = 0, len = message.length(); i < len; i += LOG_CHUNK_SIZE) { | ||
int end = Math.min(len, i + LOG_CHUNK_SIZE); | ||
Log.d(tag, message.substring(i, end)); | ||
} | ||
} | ||
} |