精华内容
参与话题
问答
  • 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指南)

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

    展开全文
  • 主要介绍了Flutter实战之自定义日志打印组件详解,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
  • 使用框架的功能开发错误的捕获,可以写...import 'package:flutter/foundation.dart'; import 'package:path_provider/path_provider.dart'; /// ### 记录项目日志、捕获项目错误、缓存所有记录、写入文件、上传服...

    使用框架的功能开发错误的捕获,可以写项目日志,可以记录设备信息,代码如下:

    
    import 'dart:io';
    import 'dart:async';
    import 'package:flutter/foundation.dart';
    import 'package:path_provider/path_provider.dart';
    import 'package:device_info/device_info.dart';
    
    /// ### 记录项目日志、捕获项目错误、缓存所有记录、写入文件、上传服务器
    /// * 初始化:
    /// ```dart
    /// ErrorLog.log = new ErrorLog(
    ///     reportZone: () async {
    ///         runApp(new MyApp());
    ///     },
    ///     debugMode: true,
    ///     uploadFile: (file) async {},
    ///     minutesWait: 30,
    ///     [fileName: 'error_log.txt']
    /// );
    /// ```
    /// 
    /// ### 项目日志
    /// 默认标记的项目日志可以使用相应的方法;自定义标记的项目日志可以使用基础方法。
    /// * 使用方式:
    /// ```dart
    /// ErrorLog.log.debug('msg'*8);
    /// ErrorLog.log.info('msg'*8);
    /// ErrorLog.log.warn('msg'*8);
    /// ErrorLog.log.error('msg'*8);
    /// ErrorLog.log.fatal('msg'*8);
    /// ErrorLog.log.collectLog('msg'*8, 'error');  // 都是调用这个基础方法
    /// ```
    /// * 输出格式:
    /// #### [2019-04-18 11:50:29.844858][error] msgmsgmsgmsgmsgmsgmsgmsg
    /// 
    /// ### 错误报告
    /// 错误报告的信息比较多,标记为`report`。
    /// * 使用方式:
    /// 自动捕获错误,不包含 `try/catch`,不包含 `print`。
    /// * 输出格式:
    /// #### [2019-04-18 14:05:03.578755][report]
    /// #### 所有错误信息
    /// 
    /// ### 写入文件
    /// 所有记录都缓存在一个数组里,如果`debugMode`为真,打印到控制台;
    /// 否则根据数组索引异步写入文件`error_log.txt`,在初始化时可传参`fileName`。
    /// * 使用方式:
    /// ```dart
    /// ErrorLog.log.printBuffer();  // 打印记录缓存
    /// ErrorLog.log.clearFile();    // 清空记录文件
    /// ErrorLog.log.printFile();    // 打印文件内容
    /// ```
    /// 
    /// ### 上传服务器
    /// 打开应用时上传一次,然后设置计时器,建议30分钟上传一次。调试模式下,没有写入文件,不会调用上传接口。
    /// * 使用方式:
    /// 初始化时传参`uploadFile`和`minutesWait`,获取记录的文件`ErrorLog.log.logFile`。
    /// 
    /// ### 设备信息
    /// 使用 [device_info](https://pub.dartlang.org/packages/device_info),应用启动时会获取和记录。
    /// * 使用方式:
    /// ```dart
    /// await ErrorLog.log.getDeviceInfo();   // 异步返回设备信息
    /// ```
    /// * 输出格式:
    /// 字符串,Future<String>
    /// #### [2019-04-24 10:05:11.413469][info] 设备信息 [device_info](https://pub.dartlang.org/packages/device_info)
    /// #### [androidInfo] androidId: 1a08f53b320ccfef, ...
    /// 
    class ErrorLog {
    
      /// 实例,静态属性
      static ErrorLog log;
    
      /// 捕获错误的区域
      Function _reportZone;
    
      /// 是否调试模式
      bool _debugMode;
    
      /// 缓存记录的数组
      List<String> _logBuffer;
    
      /// 文件记录
      File _logFile;
      File get logFile => _logFile;
    
      /// 文件记录的起点
      int _startIndex;
    
      /// 文件记录的终点
      int _endIndex;
    
      /// 上传记录文件
      Function _uploadFile;
    
      /// 上传时间间隔
      int _minutesWait;
    
      /// 记录文件是否变化
      bool _fileChange;
    
      /// 记录文件的名称
      String fileName;
    
      ErrorLog({
        @required Function reportZone, 
        @required bool debugMode,
        @required Function uploadFile,
        @required int minutesWait,
        this.fileName = 'error_log.txt'
      }) {
        
        _reportZone = reportZone;
        _debugMode = debugMode;
        _uploadFile = uploadFile;
        _minutesWait = minutesWait;
        
        init();
    
      }
    
      /// 初始化
      void init() async {
    
        _logBuffer = [];
        _startIndex = 0;
        _endIndex = 0;
        _fileChange = false;
    
        FlutterError.onError = (FlutterErrorDetails details) {
          reportError(details);
        };
    
        runZoned(
          _reportZone, 
          onError: (Object obj, StackTrace stack) {
            var details = makeDetails(obj, stack);
            reportError(details);
          }
        );
    
        _logFile = await _getLocalFile();
        info('应用启动成功。');
        getDeviceInfo();
    
        if( !_debugMode ) _uploadFile(_logFile);
        Timer.periodic(Duration(minutes: _minutesWait), (timer) async {
    
          if ( _fileChange && !_debugMode ) {
            await _uploadFile(_logFile);
            _fileChange = false;
          }
          
        });
        
      }
    
    
      /// * 获取设备信息
      /// * [device_info](https://pub.dartlang.org/packages/device_info)
      Future<String> getDeviceInfo() async {
    
        DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
        String details = '设备信息[device_info](https://pub.dartlang.org/packages/device_info)\n ';
        
        try {
    
          IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
    
          details += '[iosInfo] identifierForVendor: ${iosInfo.identifierForVendor}, ';
          details += 'isPhysicalDevice: ${iosInfo.isPhysicalDevice}, ';
          details += 'localizedModel: ${iosInfo.localizedModel}, ';
          details += 'model: ${iosInfo.model}, ';
          details += 'name: ${iosInfo.name}, ';
          details += 'systemName: ${iosInfo.systemName}, ';
          details += 'systemVersion: ${iosInfo.systemVersion}. ';
    
          details += '\n [iosInfo.utsname] machine: ${iosInfo.utsname.machine}, ';
          details += 'nodename: ${iosInfo.utsname.nodename}, ';
          details += 'release: ${iosInfo.utsname.release}, ';
          details += 'sysname: ${iosInfo.utsname.sysname}, ';
          details += 'version: ${iosInfo.utsname.version}. ';
    
        } catch(e) {
          error('无法获取 ios 设备信息。');
        }
    
        try {
    
          AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
    
          details += '[androidInfo] androidId: ${androidInfo.androidId}, ';
          details += 'board: ${androidInfo.board}, ';
          details += 'bootloader: ${androidInfo.bootloader}, ';
          details += 'brand: ${androidInfo.brand}, ';
          details += 'device: ${androidInfo.device}, ';
          details += 'display: ${androidInfo.display}, ';
          details += 'fingerprint: ${androidInfo.fingerprint}, ';
          details += 'hardware: ${androidInfo.hardware}, ';
          details += 'host: ${androidInfo.host}, ';
          details += 'id: ${androidInfo.id}, ';
          details += 'isPhysicalDevice: ${androidInfo.isPhysicalDevice}, ';
          details += 'manufacturer: ${androidInfo.manufacturer}, ';
          details += 'model: ${androidInfo.model}, ';
          details += 'product: ${androidInfo.product}, ';
          details += 'supported32BitAbis: ${androidInfo.supported32BitAbis}, ';
          details += 'supported64BitAbis: ${androidInfo.supported64BitAbis}, ';
          details += 'supportedAbis: ${androidInfo.supportedAbis}, ';
          details += 'tags: ${androidInfo.tags}, ';
          details += 'type: ${androidInfo.type}. ';
    
          details += '\n [androidInfo.version] baseOS: ${androidInfo.version.baseOS}, ';
          details += 'codename: ${androidInfo.version.codename}, ';
          details += 'incremental: ${androidInfo.version.incremental}, ';
          details += 'previewSdkInt: ${androidInfo.version.previewSdkInt}, ';
          details += 'release: ${androidInfo.version.release}, ';
          details += 'sdkInt: ${androidInfo.version.sdkInt}, ';
          details += 'securityPatch: ${androidInfo.version.securityPatch}. ';
    
        } catch(e) {
          error('无法获取 android 设备信息。');
        }
    
        info(details);
        return details;
        
      }
    
    
      /// 错误报告
      void reportError(FlutterErrorDetails details) {
    
        String errorMeta = '[' + (new DateTime.now().toString()) + '][report]';
        _logBuffer.add(errorMeta + '\n' + details.toString());
    
        if (_debugMode) {
          print(errorMeta);
          print(details.toString());
        } else {
          _writeFile();
        }
        
      }
    
      /// 项目日志
      collectLog(String line, String label) {
    
        String contents = '[' + (new DateTime.now().toString()) + '][' + label + '] ' + line;
        _logBuffer.add(contents + '\n');
    
        if (_debugMode) {
          print(contents);
        } else {
          _writeFile();
        }
        
      }
    
    
      /// 打印文件
      Future<Null> printFile() async {
        _readLocalFile().then((contents) {
          print(contents);
        });
      }
    
      /// 打印缓存
      Future<Null> printBuffer() async {
        print( _logBuffer.toString() );
      }
    
      /// 清空文件
      Future<Null> clearFile() async {
        await _logFile.writeAsString('', mode: FileMode.write);
      }
    
      /// 实时写入文件,防止意外
      Future<Null> _writeFile() async {
    
        int len = _logBuffer.length;
        if (len > _endIndex) {
          _startIndex = _endIndex;
          _endIndex = len;
          Iterable<String> range = _logBuffer.getRange(_startIndex, _endIndex);
          await _writeLocalFile( range.join('\n') );
          _fileChange = true;
        } 
    
      }
    
      /// 获取文件
      Future<File> _getLocalFile() async {
        String dir = (await getApplicationDocumentsDirectory()).path;
        return new File('$dir/' + fileName);
      }
    
      /// 读取文件
      Future<String> _readLocalFile() async {
        String contents = await _logFile.readAsString();
        return contents;
      }
    
      /// 写入文件
      Future<Null> _writeLocalFile(String contents) async {
        await _logFile.writeAsString(contents, mode: FileMode.append, flush: false);
      }
    
    
      /// 构建错误信息
      FlutterErrorDetails makeDetails(Object obj, StackTrace stack) {
        return FlutterErrorDetails(exception: obj, stack: stack);
      }
    
      /// 调试
      void debug(String msg) {
        collectLog(msg, 'debug');
      }
    
      /// 信息
      void info(String msg) {
        collectLog(msg, 'info');
      }
    
      /// 警告
      void warn(String msg) {
        collectLog(msg, 'warn');
      }
    
      /// 错误
      void error(String msg) {
        collectLog(msg, 'error');
      }
    
      /// 致命错误
      void fatal(String msg) {
        collectLog(msg, 'fatal');
      }
    
    }
    
    

    参考的文档:
    文件操作
    异常捕获
    日志处理
    设备信息

    展开全文
  • 最简单的日志收集方式,支持所有平台。 默认情况下,日志会被上传到avenge.cn,这是一个简单的日志管理系统,欢迎试用_ 你也可以设置自己的服务器来接收日志。 开始 注册账号 https://avenge.cn/register 创建...

    simple_log

    最简单的日志收集方式,支持所有平台。

    默认情况下,日志会被上传到avenge.app,这是一个简单的日志管理系统,欢迎试用_

    你也可以设置自己的服务器来接收日志。

    开始

    1. 注册账号

      https://avenge.app/register

    2. 创建应用

      https://avenge.app/developer/resources/apps/new

    3. 安装扩展

      dependencies:
          simple_log: ^1.2.0
      
    4. 用法

      import 'package:simple_log/simple_log.dart';
      
      void main(){
        SimpleLog logger = SimpleLog(appId: yourAppId, appKey: 'yourAppKey');
        FlutterError.onError = (FlutterErrorDetails details) {
          logger.e(details);
        };
        runApp(MyApp());
      }
      
    5. 其他用法

      simple_logger_example.dart

      SimpleLog logger = SimpleLog(appId: 123, appKey: 'yourAppKey');
      SimpleLog logger2 = SimpleLog(key: 'key2',appId: 456, appKey: 'yourAppKey2');
      
      // key默认值为'default'
      assert(logger == SimpleLog(key: 'default'));
      
      // debug等级
      logger.d('hello world');
      
      // info等级 
      logger.i('hello world');
      
      // warning等级 
      logger.w({'a':1,'b':'c'}); 
      
      // 设置本地打印日志的等级,error等级的日志会被打印在本地终端
      logger2.setPrintLevels([Level.Error]);
      
      // error等级
      // 此日志会被打印在本地终端
      logger2.e(logger); 
      
      // 取消上传日志
      logger2.setUploadLevels(null);
      
      // fatal等级
      // 此日志会被打印在本地终端,但不会上传
      logger2.f(['p1', 'p2']); 
      

    构建接收日志服务器

    SimpleLog.apiPrefix 的默认值是 https://avenge.app/api ,你可以指定自己的服务器来接收日志。

    var logger = SimpleLog(apiPrefix: 'your own server');
    

    当提交一个日志时,它会向服务器发送一个json:

    {
      "app_id": 123,
      "app_key": "appKey123",
      "user": "user123",
      "flag": "flag123",
      "level": 2,
      "data": {}
    }
    

    data 是这个日志的内容,可以是字符串,也可以是json。

    然后,服务器会返回json:

    {
      "code": 0,
      "message": "success"
    }
    

    如果 code 值是 0 ,意味着提交成功。

    如果发生了错误,将会是:

    {
      "code": -1,
      "message": "something wrong ..."
    }
    

    全部项目

    插件 描述
    simple_log 最简单的日志收集方式,支持所有平台
    simple_update 最简单的应用更新方式,支持所有平台

    Avenge应用商店

    avenge.app

    展开全文
  • 输出一个完整的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("");
      }
    }
    
    展开全文
  • flutter 提供了 print(Object object) 来向开发工具的控制 台输出日志信息 print("test"); common_utils 工具类已经将pring 封装为工具类 common_utils: ^1.1.1 使用common_utils工具类中的LogUtil //初始化设置 ...
  • flutter日志工具

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

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

    千次阅读 2019-03-16 13:14:16
    Flutter中,如果我们需要打印日志,如果不进行自定义,我们只能使用自带的print()或者debugPrint()方法进行打印,但是这两种打印,日志都是默认Info层级的日志,很不友好,所以如果需要日志打印层级分明,我们就...
  • Flutter

    千次阅读 2019-09-27 11:00:21
    作为谷歌的开源移动UI框架,Flutter可以快速在iOS和Android上构建高质量的原生用户界面,2019年,Google I/O 大会宣布了 flutter 支持 web 开发。flutter 目前的目的就是全平台开发,一套代码同时运行在 iOS 、...
  • Flutter Dart print 日志打印

    千次阅读 2019-10-14 15:03:28
    print('我是日志'); String name = '野猿新一'; print('我的名字叫${name}'); 没啦,就这么简单
  • 显然这是android studio的bug,不知道为什么到最新4.0版本也没有修复,妥协的办法是关联androidSDK,底部会出现logcat,然后可以像普通的android App开发那样看日志,或者在Terminal窗口直接输入flutter run运行项目...
  • flutter 屏幕适配 字体大小适配

    万次阅读 热门讨论 2018-09-21 00:08:21
    前言: 现在的手机品牌和型号越来越多,导致我们平时写布局的时候会在个不同的移动设备上显示的效果不同, 比如我们的设计稿一个View的大小是300px,如果直接写300px,可能在当前设备显示...而flutter本身并没有适...
  • flutter的log过滤,快速定位代码异常

    千次阅读 2019-01-22 02:27:22
    相信很多人刚用flutter的时候,看到自带的异常捕捉log打印都懵圈过,即使是上手之后,也不能快速的找到对应的异常代码行数 前言 在寻找开源库的时候,发现了一个dart团队做的可以调整log格式的库,但是很遗憾这个库...
  • FLUTTER

    千次阅读 2018-12-06 16:11:28
    安装FLUTTER 官方教程: https://codelabs.flutter-io.cn/codelabs/first-flutter-app-pt1-cn/index.html#1 下载Flutter的SDK...
  • flutter开发之dart语言

    千人学习 2018-12-27 09:56:49
    flutter是谷歌的移动ui框架,可以快速在ios和android上构建高质量的用户界面。dart是flutter的官方语言,所以掌握dart语言是开发flutter应用的必备技能。
  • Flutter-常用插件汇总

    千次阅读 2019-07-31 16:42:11
    flutter_sound: ^1.1.5#录音 dropdown_menu: ^1.1.0#下拉菜单 simple_permissions:#权限获取 easy_alert:#弹框 amap_location: any #高德地图 location: any #gogle位置获取 barcode_scan 0...
  • Flutter中文乱码解析

    千次阅读 2018-11-08 13:11:48
    今天遇到了Fluter请求下来的中文数据会出现乱码的问题,尝试了很多网上搜索的办法,无非就只试一些引用gbk2utf8这个库,但是实际使用过程中根本没有任何作用,可以说是根本一点软用都没有(不好意思,因为误导了我...
  • flutter umeng 极光 友盟 统计

    千次阅读 2019-12-28 20:05:42
    flutter_umplus: ^0.0.1 flutter_jpush: ^0.0.4 main 方法增加以下代码 void _startupJpush() async { print("初始化jpush"); await FlutterJPush.startup(); print("初始化jpush成功"); } initUMeng() { ...
  • 背景用户行为埋点是用来记录用户在操作时的一系列行为,也是业务做判断的核心数据依据,如果缺失或者不准确将会给业务带来不可恢复的损失。闲鱼将业务代码从Native迁移到Flu...
  • Kotlin vs Flutter,我到底应该怎么选?

    万次阅读 多人点赞 2020-01-17 08:05:15
    在移动应用开发方面,Kotlin和Flutter是目前比较火热的两门技术。其中,Kotlin是由Jetbrains研发,后被Google大力扶持,Flutter则是由Google自己独立研发的。从目前Google官方的态度来看,这两门技术都被无限看好,...
  • 求助怎么变回正常的样子,看着闹心啊,android项目正常,就flutter的这样 ![图片说明](https://img-ask.csdn.net/upload/202005/09/1589010817_360318.jpg)
  • flutter基础教程

    万人学习 2018-08-27 15:50:34
    Flutter基础入门视频教程,Flutter是谷歌的移动UI框架,可以快速在iOS和Android上构建高质量的原生用户界面。通过这门课程的学习使得大家掌握使用flutter来编写跨平台移动客户端应用。
  • flutter,打开Logcat视窗

    2020-07-09 20:23:26
    后来发现flutter项目自动打印出来的日志都是没有时间的,神经病一样。后来就想啊,是不是可以调出Logcat呢,还真嫩。 解决方法: 点击 或者找到Project Structure菜单,进入,找到Facets,点击+,, 选择Android...
  • 项目地址 基于dart官方stack_trace开发 ...I/flutter ( 3068): PlatformException(error, Attempt to invoke virtual method 'java.lang.String java.lang.Object.toString()' on a null object reference, null) I...
  • 这个是我粘贴复制来的,做个随笔记录。看见好几个平台都有,也不知道最初是谁整理的,就不贴原作者了。。。 漂亮的开源库 第三方库 ... 网络...
  • flutter 的像素尺寸

    万次阅读 热门讨论 2019-09-24 08:49:25
    但是在flutter中写尺寸是没有单位的。如: SizedBox(height: 736,width: 375,child: Container(color: Colors.lightBlueAccent) ) 实际上它的尺寸当然是有的。 在不同设备中它与devicePixelRatio 属性有关,通过...
  • flutter、rn、uni-app比较

    万次阅读 多人点赞 2019-08-28 16:30:46
    转自:DCloud社区 uni-app频道的文章Flutter、RN、uni-app比较 前言 每当我们评估新技术时要问的第一个问题就是“它会给我们的业务和客户带来哪些价值?”,工程师们很容易对闪闪发光的新事物着迷,却经常会忽略...
  • Flutter解密

    千次阅读 2018-08-16 14:47:34
    Flutter:谷歌的移动端UI开源框架,2018年2月27日, Google发布了Flutter的第一个Beta版本。它是Google使用Dart语言开发的移动应用开发框架,使用Dart代码构建高性能、高保真的iOS和Android应用程序。Flutter的工具...
  • flutter 轮播组件 Swiper

    万次阅读 热门讨论 2018-09-19 19:18:54
    flutter_swiper flutter最强大的siwiper, 多种布局方式,无限轮播,Android和IOS双端适配. 先放上github上的几张图看一下效果。 ✨✨ 新功能 更多 截图 图就先放到这里,我们看一下用法。 安装 ...

空空如也

1 2 3 4 5 ... 20
收藏数 69,987
精华内容 27,994
关键字:

flutter日志