2010-01-04 73 views
20

因为我们使用logcat作为android的控制台。 有些情况下,输出文本/味精有点大,我看不到完整的输出。 日志猫只显示它的起始部分。 有没有办法扩展它,以便我可以看到完整的味精?如何在logcat中看到长文本/味精?

+1

啊.. 我通常把它复制到从DDMS – Samuh 2010-01-04 08:42:44

+0

一个文本编辑器,我认为这是唯一的出路 – Bohemian 2010-01-04 09:01:42

+1

但你不能整段文字复制,直到如果大结束。 味精在最后被剥离。 – Bohemian 2010-01-04 09:53:11

回答

3

如果要编写长消息以在logcat中查看,那么可能需要编写自己的包装器,将方法分解为多条线路上的长消息。

+0

你是否认为它是这样的:在自定义函数中调用Log.v? – OneWorld 2010-10-28 14:49:28

+1

@OneWorld - 是的,多次调用Log.v传递消息的不同部分。 – 2010-10-28 16:18:13

10

我从来不使用GUI来查看logcat输出,所以我不确定DDMS/Eclipse UI中是否有滚动条。

无论如何,你可以使用从命令行— logcat有负载的选项。

连续监视的有源器件的日志:adb logcat
要转储整个日志:adb logcat -d
要转储整个记录到文件中:adb logcat -d > log.txt
要过滤和显示特定的日志标签:adb logcat -s MyLogTag

...还有更多!

+1

我不明白这将如何帮助任何人,但有很多票。 [logcat消息在设备上被截断](http://stackoverflow.com/a/8899735/253468),所以即使您阅读通过控制台,您正在阅读截断的文本。是否有隐藏在“......以及更多”的选项?你没有告诉? – TWiStErRob 2016-09-10 09:19:44

2

当然,您可以更改列的宽度,只需点击并拖动即可。对于很长的消息来说这是一个痛苦。如果我有一个非常长的消息,我通常会复制该行并将其粘贴到文本文件中。 Windows中的Ctrl-C将复制它。

+2

如果消息很长,Logcat会剥离文本。它不记录完整的味精。所以当我复制它时,文字也会被删除 – Bohemian 2010-01-05 05:12:40

0

要添加到Jay Askren的答案中,您还可以双击“文本”列标题的右边缘以将其完全展开。我注意到,即使如此,Eclipse会显示的字符数也是有限制的。

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); 
     } 
    } 
}