精华内容
下载资源
问答
  • 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());
      }
    }
    
    

    完毕 每日积累 尽在点滴

    展开全文
  • flutter日志工具

    2020-03-18 18:32:27
    以前用惯了as的logcat,现在在接触flutter,但是打印日志窗口真的让我蒙了,啥功能都没有,于是自己写了一个小工具,至少分下类过滤一下 class LogUtils { static const bool debug = true; //显示debug,info,...

    以前用惯了as的logcat,现在在接触flutter,但是打印日志窗口真的让我蒙了,啥功能都没有,于是自己写了一个小工具,至少分下类过滤一下

    class LogUtils {
    
      static const bool debug = true;
    
      //显示debug,info,error
      static const bool showDebug = false;
    
      //显示info,error
      static const bool showInfo = true;
    
      //显示error
      static const bool showError = true;
    
      static const int LEVEL_DEBUG = 0;
      static const int LEVEL_INFO = 1;
      static const int LEVEL_ERROR = 2;
    
      static void d(String tag, Object message) {
          _printLog(tag, LEVEL_DEBUG, message);
      }
    
      static void i(String tag, Object message) {
          _printLog(tag, LEVEL_INFO, message);
      }
    
      static void e(String tag, Object message) {
          _printLog(tag, LEVEL_ERROR, message);
      }
    
      static void _printLog(String tag, int level, Object message) {
        String flag;
        bool show;
        switch (level) {
          case LEVEL_DEBUG:
            flag = 'D->';
            show =showDebug;
            break;
          case LEVEL_INFO:
            flag = 'I->';
            show = showInfo||showDebug;
            break;
          case LEVEL_ERROR:
            flag = 'E->';
            show = showError||showInfo||showDebug;
            break;
        }
        StringBuffer sb = new StringBuffer();
        sb..write(flag)..write(tag ?? "")..write(':')..write(message);
        if(show&&debug){
          print(sb.toString());
        }
      }
    }
    
    
    展开全文
  • Flutter 日志显示不全

    2021-05-14 11:59:16
    print 和debugPrint是会显示不全的 可以使用 import 'dart:developer'; log(response.body);

     print 和debugPrint是会显示不全的

    可以使用

    import 'dart:developer';
      log(response.body);

     

    展开全文
  • 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":"000kD0DI1...

    输出一个完整的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("");
      }
    }
    
    展开全文
  • flutter学习日志

    2020-06-22 16:19:55
    dart语言学习:https://www.dartcn.com/guides/language/language-tour#处理-future flutter学习中文文档:https://flutter.cn/docs/cookbook(可快速入手给Android开发者的flutter指南)
  • Flutter学习日志

    2021-04-08 09:09:17
    第001天-20210321 第002天-20210322 第003天-20210323 第004天-20210324 第005天-20210325 第006天-20210326 第007天-20210327 第008天-20210328 第009天-20210329 第010天-20210331 第011天-20210401 ...
  • Flutter异常分类 可以分为三大类 Dart异常 Framework异常 Engine异常 1. Dart异常捕获 局部捕获 //使用try-catch捕获同步异常 try { throw StateError('This is a Dart exception'); }catch(e) { print(e); } /...
  • 目标:命令行输入 flutter doctor (检测flutter所需环境) 得到下图所示-> ->->目标分解:-> 安装flutter (上图中第一个√ get) 安装jdk 安装android studio 安装android sdk (上图中第二个√ get...
  • Flutter中,如果我们需要打印日志,如果不进行自定义,我们只能使用自带的 print() 或者 debugPrint() 方法进行打印,但是这两种打印,日志都是默认 Info 层级的日志,很不友好,所以如果需要日志打印层级分明,...
  • Flutter Dart print 日志打印

    万次阅读 2019-10-14 15:03:28
    print('我是日志'); String name = '野猿新一'; print('我的名字叫${name}'); 没啦,就这么简单
  • 这里以Flutter 调用原生系统日志库,来理解下 Flutter 与 Android 交互 这里创建的时候用到了 Kotlin 、AndroidX Android端 进入 android 目录下的 build.gradle ,点击 Open for Editing in Android Studio ,...
  • flutter log4d 日志包的使用

    千次阅读 2019-03-05 16:38:31
    然后客户端(不仅是 flutter,而是只要可以使用dart:io就可以)开启远程连接,然后就可以发送日志到服务端了 好处 这样的好处是,开发机可以实时接收到日志,并且保存到文件中 因为我们很多时候会发生日志超出一个长度...
  • Flutter实战之自定义日志打印组件

    千次阅读 2019-03-16 13:14:16
    Flutter中,如果我们需要打印日志,如果不进行自定义,我们只能使用自带的print()或者debugPrint()方法进行打印,但是这两种打印,日志都是默认Info层级的日志,很不友好,所以如果需要日志打印层级分明,我们就...
  • flutter 的崩溃日志收集主要有两个方面: flutter dart 代码的异常(包含app和framework代码两种情况,一般不会引起闪退,你猜为什么) flutter engine 的崩溃日志(一般会闪退) Flutter App 代码异常捕获 人写...
  • 最简单的日志收集方式,支持所有平台。 默认情况下,日志会被上传到avenge.cn,这是一个简单的日志管理系统,欢迎试用_ 你也可以设置自己的服务器来接收日志。 开始 注册账号 https://avenge.cn/register 创建...
  • eggnstone_flutter Flutter工具的集合,包括用于日志记录,Analytics和Crashlytics的包装器。

空空如也

空空如也

1 2 3 4 5 ... 13
收藏数 247
精华内容 98
关键字:

flutter日志