精华内容
参与话题
问答
  • flutter 提供了 print(Object object) 来向开发工具的控制 台输出日志信息 print("test"); common_utils 工具类已经将pring 封装为工具类 common_utils: ^1.1.1 使用common_utils工具类中的LogUtil //初始化设置 ...

    重要消息


    目前在西瓜视频上免费刊登 Flutter 系列教程,每日更新,欢迎关注接收提醒

    【x1】点击查看提示

    【x2】各种系列的教程

    【x3】flutter 点滴积累 系列文章


    flutter 提供了 print(Object object) 来向开发工具的控制 台输出日志信息

    print("test");
    

    可以通过插值法直接输出基本数据类型如下 :

    String str ="张三"print("测试输出 $str ");
    
    int count = 40;
    print("测试输出 $count ");
    

    如果是对象类型的,比如要输出对象的一个属性的值,可以这样做:

     User user = new User(name:"张三");
     
     ///输出name
     print("测试输出 ${user.name} ");
    

    common_utils 工具类已经将pring 封装为工具类

    common_utils: ^1.1.1
    

    使用common_utils工具类中的LogUtil

    //初始化设置 LogUtil
    LogUtil.init(true);
    //输出日志
    LogUtil.v("test");
    

    当然 LogUtil 的 init 方法可根据是否是生产环境来配置 true 与 false ,如果是 false ,则不输出日志,这样的一个优化也是应用在发版本后可以节省向控制台输出日志信息的消耗。

    封装源码如下

    class LogUtil {
      static const String _TAG_DEF = "###common_utils###";
    
      static bool debuggable = false; //是否是debug模式,true: log v 不输出.
      static String TAG = _TAG_DEF;
    
      static void init({bool isDebug = false, String tag = _TAG_DEF}) {
        debuggable = isDebug;
        TAG = tag;
      }
    
      static void e(Object object, {String tag}) {
        _printLog(tag, '  e  ', object);
      }
    
      static void v(Object object, {String tag}) {
        if (debuggable) {
          _printLog(tag, '  v  ', object);
        }
      }
    
      static void _printLog(String tag, String stag, Object object) {
        StringBuffer sb = new StringBuffer();
        sb.write((tag == null || tag.isEmpty) ? TAG : tag);
        sb.write(stag);
        sb.write(object);
        print(sb.toString());
      }
    }
    
    

    完毕 每日积累 尽在点滴

    展开全文
  • 输出一个完整的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":"",...

    输出一个完整的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源码 log_util

    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("");
      }
    }
    
    展开全文
  • 看一下这三个是不是都选择上了

    看一下这三个是不是都选择上了

    展开全文
  • ios手机升级到13后,flutter调试模式下print会无效,不打印调试日志 解决方法有几种: 等官方更新,或者切到flutter的master分支,方法是执行flutter channel master。这个方法我没试过,也不推荐,业务master分支...

    ios手机升级到13后,flutter调试模式下print会无效,不打印调试日志

    解决方法有几种:

    1. 等官方更新,或者切到flutter的master分支,方法是执行flutter channel master。这个方法我没试过,也不推荐,业务master分支不是一个稳定分支。
    2. 把修正这个错误的单子合并到stable分支,因为我用的是stable分支,所以后面讲这么合并到stable分支
    1.打开命令行,cd到flutter安装目录
    2.执行git cherry-pick 2e7d913
    3.然后会提示2个文件冲突,分别是:
    	packages/flutter_tools/lib/src/ios/devices.dart.orig
    	packages/flutter_tools/test/general.shard/resident_runner_test.dart.orig
    4.执行再执行git mergetool,先合并第一个文件,如果不知道怎么合并,直接下载我附件的文件替换进去吧(仅限1.9.1+hotfix.7-pre版本);第二个文件不用合并,直接用最新的就可以
    5.git cherry-pick --continue
    6.然后使用flutter run 一个工程试试,我是直接用android studio测的,正常了
    

    后面等官方补丁出来后,直接使用flutter upgroup会有影响,要先撤销上面的修改:

    git reset HEAD~
    git reset --hard
    git clean -xdf
    
    展开全文
  • 自定义log时,往往需要我们把后台返回的json字符串格式化输出到控制台,方便我们调试。Android原生可以通过JSONObject等进行格式化,将字符串格式化。flutter中并没有那么便利的实现方式,因此需要我们手动转换。想...
  • Flutter实战之自定义日志打印组件

    千次阅读 2019-03-16 13:14:16
    前言 在Flutter中,如果我们需要打印日志,如果不进行自定义,我们只能使用自带的print()或者debugPrint()方法进行打印...如何让输出日志层级分明? 换种方式想,如果我们能在Flutter代码中,能够调用到原始Androi...
  • 在iOS调试Flutter时,默认的日志...只要在Android Studio的控制台上执行命令:flutter logs就可以Android Studio的控制台上输出日志了。 这样报错时,在控制台直接点击报错行,就可以跳转到对应的Flutter代码了。 ...
  • Flutter Engine C++ 源码调试初探

    千次阅读 2019-12-31 15:53:22
    原文:https://fucknmb.com/2019/12/06/Flutter-Engine-C-%E6%BA%90%E7%A0%81%E8%B0%83%E8%AF%95%E5%88%9D%E6%8E%A2/ 备份防丢,推荐上述链接阅读 ...调试的手段有多种,一般以日志输出和断点调试为主。本...
  • VSCode Flutter 打包APK

    千次阅读 2019-09-11 17:08:25
    build后回车,输出日志如上图。 打包好的apk保存路径及大小:Built build\app\outputs\apk\release\app-release.apk (11.2MB). 配置 VSCode默认是没有使用密钥签名的,往往我们在正式项目中是需要签名的。那就...
  • Flutter常用命令简介

    2020-05-18 23:23:50
    1.flutter -h/–help/ help 查看帮助 查看帮助信息 类似命令的使用指南 -h/--help可以作为别的命令的后缀使用 打印...--v 查看APP所有日志输出 --release/--debug/--profile/--test 分别是以release/debug/profile
  • 地址:...1、TimelineUtil : 时间轴.(新)2、TimerUtil : 倒计时,定时任务.(新)3、MoneyUtil : 精确转换,元转分,分转元,支持格式输出.(新)4、LogUtil : 简单封装打印日志.(新...
  • 活不多说,直接开始: 1、程序入口 在Dart里,每一个App都必须有一个顶级的 main() 函数...// 控制台输出日志 } 2、变量 Dart是类型安全的,它使用静态类型检查和运行时的组合,检查以确保变量的值始终与变量的...
  • 我们通过友盟去查看了一下崩溃的日志,只能看到引起崩溃的内容是flutter相关的东西,没有什么实质性的输出无法定位到具体问题。 问题复现 为了解决这个crash问题,我们想办法联系到了客户,通过testflight让用户共享...
  • Flutter应用中,导航栏切换页面后默认情况下会丢失原页面状态,即每次进入页面时都会重新初始化状态,如果在initState中打印日志,会发现每次进入时都会输出,显然这样增加了额外的开销,并且带来了不好的用户体验...
  • Android compileSdkVersion 大于等于28时,之前所有的android.support packages全部由androidx代替,如果flutter app 编译输出类似下面的日志 This version of image_picker will break your Android build if it or...
  • 汇总了实际开发中遇到的bug,包括错位日志,如何分析问题,解决问题,出现bug的场景等等。详细请点击:bug分析大汇总 05.技术问题整理 5.1 01.Java问题大整理 01.Java基础问题(19个) 02.Java面向对象问题(10...
  • 在命令行输入,gradlew compileDebugSources,可以查看打印报错的信息,这句话可以控制台输出代码报错的日志。 IOException: CreateProcess error=2, 系统找不到指定的文件。 具体报错日志如下所示 ...

空空如也

1 2
收藏数 31
精华内容 12
关键字:

flutter 日志输出