flutter日志工具

以前用惯了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());
    }
  }
}

你可能感兴趣的:(android相关)