zoukankan      html  css  js  c++  java
  • 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工具。

  • 相关阅读:
    HDU
    HDU
    HDU
    HDU
    HDU
    P6146 [USACO20FEB]Help Yourself G 组合数学 DP
    CodeForces
    POJ
    【网络学习】集线器,交换机,路由器的作用
    【Python学习】深拷贝和浅拷贝
  • 原文地址:https://www.cnblogs.com/zgz345/p/5553320.html
Copyright © 2011-2022 走看看