Flutter 로그가 너무 길어 출력이 불완전하게 되는 문제 해결 - LogUtil

전체 Json 내보내기
void main() {
      print("""{"code":200,"msg":"OK","timestamp":0,"data":[{"cover":"","sub_title":"","listen_num":0,"report":"","id":23644,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"000kD0DI1EXpLO"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1788145.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23601,"title":"","type":3002,"jump_info":{"mid":"","id":0,"url":"https://y.qq.com/m/digitalbum/gold/index.html?openinqqmusic=1&_video=true&mid=000XEFal22lEwn&g_f=yqqjiaodian"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1781138.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23646,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"
003XxGq831zlQv"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1788739.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23554,"title":"","type":3002,"jump_info":{"mid":"","id":0,"url":"https://y.qq.com/m/digitalbum/gold/index.html?openinqqmusic=1&_video=true&mid=000H3CIo2BRJCl&g_f=yqqjiaodian"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1781158.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23648,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"003VJ4rz4FltZy"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1788440.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","
id":23636,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"003BVXph3haZPj"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1783665.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23619,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"000iCavD0beBPq"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1784125.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23629,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"003HbRAe4Y8qqG"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1786011.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23617,"title":"","t
ype":10002,"jump_info":{"mid":"","id":0,"url":"000W8zPv1woZcd"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1780111.jpg","urlex1":""}}]}""");
}

실행 결과-근소량
I/flutter (25292): {"code":200,"msg":"OK","timestamp":0,"data":[{"cover":"","sub_title":"","listen_num":0,"report":"","id":23644,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"000kD0DI1EXpLO"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1788145.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23601,"title":"","type":3002,"jump_info":{"mid":"","id":0,"url":"https://y.qq.com/m/digitalbum/gold/index.html?openinqqmusic=1&_video=true&mid=000XEFal22lEwn&g_f=yqqjiaodian"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1781138.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23646,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"
I/flutter (25292): 003XxGq831zlQv"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1788739.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23554,"title":"","type":3002,"jump_info":{"mid":

jump로 출력되는 것을 볼 수 있습니다info ": {"mid ": 중단되었습니다. json을 완전히 출력하지 않았습니다.
디버깅할 때 이 데이터를 사용할 수 있지만, 로그 인쇄가 완전하지 않기 때문입니다.이 데이터를 가져오는 것을 끊어야 한다.아마 900Char 이후로는 출력을 하지 않을 거예요.따라서 지정한 limit 길이에 따라 로그 정보를 세그먼트로 인쇄합니다.LogUtil이 생겼습니다.
LogUtil 사용
void main() {
      LogUtil.d("""{"code":200,"msg":"OK","timestamp":0,"data":[{"cover":"","sub_title":"","listen_num":0,"report":"","id":23644,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"000kD0DI1EXpLO"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1788145.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23601,"title":"","type":3002,"jump_info":{"mid":"","id":0,"url":"https://y.qq.com/m/digitalbum/gold/index.html?openinqqmusic=1&_video=true&mid=000XEFal22lEwn&g_f=yqqjiaodian"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1781138.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23646,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"
003XxGq831zlQv"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1788739.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23554,"title":"","type":3002,"jump_info":{"mid":"","id":0,"url":"https://y.qq.com/m/digitalbum/gold/index.html?openinqqmusic=1&_video=true&mid=000H3CIo2BRJCl&g_f=yqqjiaodian"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1781158.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23648,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"003VJ4rz4FltZy"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1788440.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","
id":23636,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"003BVXph3haZPj"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1783665.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23619,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"000iCavD0beBPq"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1784125.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23629,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"003HbRAe4Y8qqG"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1786011.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23617,"title":"","t
ype":10002,"jump_info":{"mid":"","id":0,"url":"000W8zPv1woZcd"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1780111.jpg","urlex1":""}}]}""");
}

수행 결과 - 차이 없음
I/flutter (25762): =========Yl-Log=========
I/flutter (25762): 
I/flutter (25762): {"code":200,"msg":"OK","timestamp":0,"data":[{"cover":"","sub_title":"","listen_num":0,"report":"","id":23644,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"000kD0DI1EXpLO"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1788145.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23601,"title":"","type":3002,"jump_info":{"mid":"","id":0,"url":"https://y.qq.com/m/digitalbum/gold/index.html?openinqqmusic=1&_video=true&mid=000XEFal22lEwn&g_f=yqqjiaodian"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1781138.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23646,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"
I/flutter (25762): 003XxGq831zlQv"},"p
I/flutter (25762): ic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1788739.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23554,"title":"","type":3002,"jump_info":{"mid":"","id":0,"url":"https://y.qq.com/m/digitalbum/gold/index.html?openinqqmusic=1&_video=true&mid=000H3CIo2BRJCl&g_f=yqqjiaodian"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1781158.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23648,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"003VJ4rz4FltZy"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1788440.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","
I/flutter (25762): id":23636,"title":
I/flutter (25762): "","type":10002,"jump_info":{"mid":"","id":0,"url":"003BVXph3haZPj"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1783665.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23619,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"000iCavD0beBPq"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1784125.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23629,"title":"","type":10002,"jump_info":{"mid":"","id":0,"url":"003HbRAe4Y8qqG"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1786011.jpg","urlex1":""}},{"cover":"","sub_title":"","listen_num":0,"report":"","id":23617,"title":"","t
I/flutter (25762): ype":10002,"jump_
I/flutter (25762): info":{"mid":"","id":0,"url":"000W8zPv1woZcd"},"pic_info":{"urlex2":"","mid":"","url":"http://y.gtimg.cn/music/common/upload/MUSIC_FOCUS/1780111.jpg","urlex1":""}}]}
I/flutter (25762): 
I/flutter (25762): =====================

LogUtil
Api
	///       
	///const bool isDebug = !const bool.fromEnvironment("dart.vm.product");

	//     isDebug  true limitLength  800
	LogUtil.init(title: "  LogUtil", isDebug: isDebug,limitLength:800);
	
	var log = "    ";
	//  Debug   
	LogUtil.d(log);
	LogUtil.d("    ");
	
	//        
	LogUtil.v(log);
	LogUtil.v("    ");

LogUtil 소스 logutil
import 'package:flutter/cupertino.dart';

class LogUtil {
  static var _separator = "=";
  static var _split =
      "$_separator$_separator$_separator$_separator$_separator$_separator$_separator$_separator$_separator";
  static var _title = "Yl-Log";
  static var _isDebug = true;
  static int _limitLength = 800;
  static String _startLine = "$_split$_title$_split";
  static String _endLine = "$_split$_separator$_separator$_separator$_split";

  static void init({String title, @required bool isDebug,int limitLength}) {
    _title = title;
    _isDebug = isDebug;
    _limitLength = limitLength??=_limitLength;
    _startLine = "$_split$_title$_split";
    var endLineStr = StringBuffer();
    var cnCharReg = RegExp("[\u4e00-\u9fa5]");
    for (int i = 0; i < _startLine.length; i++) {
      if (cnCharReg.stringMatch(_startLine[i]) != null) {
        endLineStr.write(_separator);
      }
      endLineStr.write(_separator);
    }
    _endLine = endLineStr.toString();
  }

  // Debug    
  static void d(dynamic obj) {
    if (_isDebug) {
      _log(obj.toString());
    }
  }

  static void v(dynamic obj) {
    _log(obj.toString());
  }

  static void _log(String msg) {
    print("$_startLine");
    _logEmpyLine();
    if(msg.length<_limitLength){
      print(msg);
    }else{
      segmentationLog(msg);
    }
    _logEmpyLine();
    print("$_endLine");
  }

  static void segmentationLog(String msg) {
    var outStr = StringBuffer();
    for (var index = 0; index < msg.length; index++) {
      outStr.write(msg[index]);
      if (index % _limitLength == 0 && index!=0) {
        print(outStr);
        outStr.clear();
        var lastIndex = index+1;
        if(msg.length-lastIndex<_limitLength){
          var remainderStr = msg.substring(lastIndex,msg.length);
          print(remainderStr);
          break;
        }
      }
    }
  }

  static void _logEmpyLine(){
    print("");
  }
}

좋은 웹페이지 즐겨찾기