reportError method

Future<void> reportError(
  1. String eventName,
  2. Object? error,
  3. StackTrace stackTrace
)

异常捕获

Implementation

Future<void> reportError(String eventName, Object? error, StackTrace stackTrace) async {
  try {
    final Map<String, dynamic> output = {
      "time": Jiffy.now().format(pattern: 'yyyy-MM-dd HH:mm:ss'),
      "eventName": eventName,
      "error": indentMultilineText(error?.toString() ?? 'null', spaces: 14),
      "stackTrace": indentMultilineText(stackTrace.toString().split('\n').take(20).join('\n'), spaces: 24),
      ..._singleLogDeviceParams,
    };
    UtilPrint.error(eventName, error, stackTrace);
    _logQueue.addToQueue(
      path: p.join(dateRootPath, 'application.txt'),
      content: normalizeFileContentError(output),
      mode: FileMode.append,
    );
  } catch (e, stackTrace) {
    debugPrint('日志服务 - 异常捕获: $e\n$stackTrace');
  }
}