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