Created
July 25, 2016 02:09
-
-
Save dzwillpower/54664ba2afe67d2737d68f6271e757ef to your computer and use it in GitHub Desktop.
android log分割类 默认的log 打印不完全所有的log
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
package com.ipanel.join.cq.vod.utils; | |
import java.util.ArrayList; | |
import android.util.Log; | |
public class LogcatUtils { | |
/** | |
* Divides a string into chunks of a given character size. | |
* | |
* @param text | |
* String text to be sliced | |
* @param sliceSize | |
* int Number of characters | |
* @return ArrayList<String> Chunks of strings | |
*/ | |
public static ArrayList<String> splitString(String text, int sliceSize) { | |
ArrayList<String> textList = new ArrayList<String>(); | |
String aux; | |
int left = -1, right = 0; | |
int charsLeft = text.length(); | |
while (charsLeft != 0) { | |
left = right; | |
if (charsLeft >= sliceSize) { | |
right += sliceSize; | |
charsLeft -= sliceSize; | |
} else { | |
right = text.length(); | |
aux = text.substring(left, right); | |
charsLeft = 0; | |
} | |
aux = text.substring(left, right); | |
textList.add(aux); | |
} | |
return textList; | |
} | |
/** | |
* Divides a string into chunks. | |
* | |
* @param text | |
* String text to be sliced | |
* @return ArrayList<String> | |
*/ | |
public static ArrayList<String> splitString(String text) { | |
return splitString(text, 2000); | |
} | |
/** | |
* Divides the string into chunks for displaying them into the Eclipse's | |
* LogCat. | |
* | |
* @param text | |
* The text to be split and shown in LogCat | |
* @param tag | |
* The tag in which it will be shown. | |
*/ | |
public static void splitAndLog(String tag, String text) { | |
ArrayList<String> messageList = LogcatUtils.splitString(text); | |
for (String message : messageList) { | |
Log.d(tag, message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment