log_util.dart 1.07 KB
import 'package:wow_english/common/request/basic_config.dart';

enum LogLevel { debug, info, warning, error }

class Log {
  static LogLevel level = BasicConfig().isTestDev ? LogLevel.debug : LogLevel.error;

  /// debug
  static void d(Object? object) {
    if (level.index <= LogLevel.debug.index) {
      String line = "$object";
      print(line);
    }
  }

  /// info
  static void i(Object? object) {
    if (level.index <= LogLevel.info.index) {
      String line = "$object";
      print(line);
    }
  }

  /// warning
  static void w(Object? object) {
    if (level.index <= LogLevel.warning.index) {
      String line = "$object";
      print(line);
    }
  }

  /// error
  static void e(Object? object) {
    if (level.index <= LogLevel.error.index) {
      String line = "$object";
      print(line);
    }
  }
}

extension LogExtension on Object? {
  Object? logD() {
    Log.d(this);
    return this;
  }

  Object? logI() {
    Log.i(this);
    return this;
  }

  Object? logW() {
    Log.w(this);
    return this;
  }

  Object? logE() {
    Log.e(this);
    return this;
  }
}