因为我们使用 logcat 作为 android 的控制台。有些情况下输出文本/消息有点大,我看不到完整的输出。日志猫只显示它的开始部分。有没有办法扩展它以便我可以看到完整的消息?
问问题
16074 次
5 回答
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);
}
}
}
于 2012-04-20T19:37:54.867 回答
10
我从不使用 GUI 来查看 logcat 输出,所以我不确定 DDMS/Eclipse UI 中哪里/是否有滚动条。
无论如何,您可以从命令行使用 logcat — 有很多选项。
持续查看活动设备adb logcat
的日志: 转储整个日志: 将adb logcat -d
整个日志转储到文件:adb logcat -d > log.txt
过滤并显示特定日志标签:adb logcat -s MyLogTag
...以及更多!
于 2010-01-05T03:34:39.043 回答
3
如果您想编写长消息以查看它可能值得围绕将长消息拆分为多行logcat
的方法编写自己的包装器。android.util.Log
于 2010-01-04T10:21:12.677 回答
2
当然,您可以更改列宽,只需点击并拖动到行尾即可。对于非常长的消息来说,这是一种痛苦。如果我的消息很长,我通常会复制该行并将其粘贴到文本文件中。Windows 中的 Ctrl-C 将复制它。
于 2010-01-05T04:19:50.263 回答
0
要添加到 Jay Askren 的答案,您还可以双击“文本”列标题的右边缘以将其完全展开。我注意到即使如此,Eclipse 将显示的字符数也是有限的。
于 2012-02-14T21:14:58.280 回答