Android adb logcat輸出日志顯示不全解決方案


在終端中使用adb logcat打印服務器json數據,如果返回數據過大超過4000字節(4K)即會截斷不顯示

原因:logcat在對於message的內存分配大概是4k左右.所以超過的內容都直接被丟棄;

解決方案:切分超過4k的message,使用多個Log.i輸出

public static void showLog(String str) {
            str = str.trim();
            int index = 0;
            int maxLength = 4000;
            String finalString;
            while (index < str.length()) {
                if (str.length() <= index + maxLength) {
                    finalString = str.substring(index);
                } else {
                    finalString = str.substring(index, maxLength);
                }
                index += maxLength;
                LogHelper.i("str", finalString.trim());
            }
 }

如果想研究源代碼,請簡單參照如下:

 Logcat工具源代碼位於system/core/logcat目錄下,只有一個源代碼文件logcat.cpp,編譯后生成的可執行文件位於out/target/product/generic/system/bin目錄下,在模擬機中,可以在/system/bin目錄下看到logcat工具。

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM