flutter 日誌輸出,Flutter打印日誌,flutter log,flutter 真機日誌

重要消息git


flutter 提供了 print(Object object) 來向開發工具的控制 臺輸出日誌信息web

print("test");

common_utils 工具類已經將pring 封裝爲工具類svg

common_utils: ^1.1.1

使用common_utils工具類中的LogUtil工具

//初始化設置 LogUtil
LogUtil.init(true);
//輸出日誌
LogUtil.v("test");

封裝源碼以下開發工具

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());
  }
}