首页 > 移动平台 > 详细

Android adb logcat输出日志显示不全解决方案

时间:2016-06-02 16:23:45      阅读:353      评论:0      收藏:0      [点我收藏+]

在终端中使用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工具。

 

Android adb logcat输出日志显示不全解决方案

原文:http://www.cnblogs.com/zgz345/p/5553320.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!