美文网首页
Android studio控制台log输出不完全

Android studio控制台log输出不完全

作者: _L丶丶 | 来源:发表于2020-08-27 14:17 被阅读0次
    项目开发中,在接口联调的时候,经常需要将后台返回的数据打印出来,但是有时候,
    后台返回的数据中如果带有list,往往数据量会很大,咱们在使用log打印的时候,经常会log只
    显示了一部分,后面就没有的情况,这种时候可以用下面的解决方案
    
    /**
     * log日志信息过长,控制台显示不全解决办法
     */
    public class MyLog {
        //可以全局控制是否打印log日志
        private static boolean isPrintLog = true;
        private static int LOG_MAXLENGTH = 3000;
    
        public static void v(String msg) {
            v("MyLog", msg);
        }
    
        public static void v(String tagName, String msg) {
            if (isPrintLog) {
                int strLength = msg.length();
                int start = 0;
                int end = LOG_MAXLENGTH;
                for (int i = 0; i < 100; i++) {
                    if (strLength > end) {
                        Log.v(tagName + i, msg.substring(start, end));
                        start = end;
                        end = end + LOG_MAXLENGTH;
                    } else {
                        Log.v(tagName + i, msg.substring(start, strLength));
                        break;
                    }
                }
            }
        }
    
        public static void d(String msg) {
            d("MyLog", msg);
        }
        public static void d(String tagName, String msg) {
            if (isPrintLog) {
                int strLength = msg.length();
                int start = 0;
                int end = LOG_MAXLENGTH;
                for (int i = 0; i < 100; i++) {
                    if (strLength > end) {
                        Log.d(tagName + i, msg.substring(start, end));
                        start = end;
                        end = end + LOG_MAXLENGTH;
                    } else {
                        Log.d(tagName + i, msg.substring(start, strLength));
                        break;
                    }
                }
            }
        }
    
        public static void i(String msg) {
            i("MyLog", msg);
        }
    
        public static void i(String tagName, String msg) {
            if (isPrintLog) {
                int strLength = msg.length();
                int start = 0;
                int end = LOG_MAXLENGTH;
                for (int i = 0; i < 100; i++) {
                    if (strLength > end) {
                        Log.i(tagName + i, msg.substring(start, end));
                        start = end;
                        end = end + LOG_MAXLENGTH;
                    } else {
                        Log.i(tagName + i, msg.substring(start, strLength));
                        break;
                    }
                }
            }
        }
    
        public static void w(String msg) {
            w("MyLog", msg);
        }
    
        public static void w(String tagName, String msg) {
            if (isPrintLog) {
                int strLength = msg.length();
                int start = 0;
                int end = LOG_MAXLENGTH;
                for (int i = 0; i < 100; i++) {
                    if (strLength > end) {
                        Log.w(tagName + i, msg.substring(start, end));
                        start = end;
                        end = end + LOG_MAXLENGTH;
                    } else {
                        Log.w(tagName + i, msg.substring(start, strLength));
                        break;
                    }
                }
            }
        }
    
        public static void e(String msg) {
            e("MyLog", msg);
        }
        public static void e(String tagName, String msg) {
            if (isPrintLog) {
                int strLength = msg.length();
                int start = 0;
                int end = LOG_MAXLENGTH;
                for (int i = 0; i < 100; i++) {
                    if (strLength > end) {
                        Log.e(tagName + i, msg.substring(start, end));
                        start = end;
                        end = end + LOG_MAXLENGTH;
                    } else {
                        Log.e(tagName + i, msg.substring(start, strLength));
                        break;
                    }
                }
            }
        }
    }
    

    将原本整段的长log分段打印,这样就可以了,ok,就是这样...

    相关文章

      网友评论

          本文标题:Android studio控制台log输出不完全

          本文链接:https://www.haomeiwen.com/subject/eyguuctx.html