Boh*_*ian 20 console android logcat
因为我们使用logcat作为android的控制台.有些情况下输出文本/消息有点大,我看不到完整的输出.log cat仅显示它的起始部分.有没有办法扩展它,以便我可以看到完整的消息?
ree*_*tor 15
这是我解决问题的方法.希望能帮助到你.
在代码中使用它的重要方法是splitAndLog.
public class Utils {
/**
* 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, 80);
}
/**
* 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 = Utils.splitString(text);
for (String message : messageList) {
Log.d(tag, message);
}
}
}
Run Code Online (Sandbox Code Playgroud)
Chr*_*Orr 10
我从不使用GUI来查看logcat输出,所以我不确定DDMS/Eclipse UI中的滚动条在哪里/是否存在.
无论如何,您可以从命令行使用logcat - 有很多选项.
要连续监视活动设备adb logcat
的日志:转储整个日志:adb logcat -d
要将整个日志转储到文件:adb logcat -d > log.txt
要过滤并显示特定的日志标记:adb logcat -s MyLogTag
...以及更多!
归档时间: |
|
查看次数: |
15398 次 |
最近记录: |