我怎样才能在logcat中查看长文本/消息?
题
由于我们使用的logcat作为机器人的控制台。 在有些情况下,当输出文本/味精是有点大,我无法看到完整的输出。 日志猫只显示它的开始部分。 有没有办法将其展开,这样我可以看到完整的味精?
解决方案
如果你想写长消息在logcat
它可能是值得写在其周围多行将您的长消息android.util.Log
方法自己的包装看。
其他提示
这是我解决了这个问题的方式。希望它帮助。
使用它的代码内的重要的方法是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);
}
}
}
我从未使用GUI视图logcat的输出,所以我不知道在哪里/是否有在DDMS / Eclipse的UI滚动条。
总之,可以使用的logcat从命令行 - 有选项负载
要观看的有源器件不断的日志:搜索adb logcat
要转储整个日志:adb logcat -d
结果
要转储整个日志文件:adb logcat -d > log.txt
结果
到过滤器,并显示特定日志标签:adb logcat -s MyLogTag
...等等!
当然,你可以通过转到线点击的端部和拖动改变列宽。这是很长的消息的痛苦。如果我有一个很长的消息,我通常复制的行并将其粘贴到一个文本文件中。 CTRL-C在Windows将复制它。
要添加到周杰伦阿斯克伦的答案,你也可以在“文本”列标题的右边缘双击全面展开。我注意到,即便如此还有以Eclipse将显示字符数的限制。
不隶属于 StackOverflow