如何在logcat中查看长文本/ msg?

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

...以及更多!

  • 我不知道这会如何帮助任何人,但却有很多选票.[logcat消息在设备上被截断](http://stackoverflow.com/a/8899735/253468),因此即使您阅读了通过控制台,您也正在阅读截断的文本.是否有一个选项隐藏在"......还有更多!" 你不是在说什么? (2认同)

Dav*_*ebb 3

如果您想编写长消息以在其中查看,logcat可能值得围绕android.util.Log将长消息拆分为多行的方法编写自己的包装器。