error static method

void error(
  1. Object error, [
  2. String? message,
  3. StackTrace? stackTrace
])

Implementation

static void error(Object error, [String? message, StackTrace? stackTrace]) {
  final timestamp = DateTime.now().toIso8601String();

  // Use print() in release mode for web to ensure logs appear in production
  void logOutput(String msg) {
    if (kReleaseMode && kIsWeb) {
      // ignore: avoid_print
      print(msg);
    } else {
      debugPrint(msg);
    }
  }

  if (message != null) {
    logOutput('[$timestamp] MESSAGE: $message');
    _onLogFunction?.call(message);
  }

  logOutput('[$timestamp] ERROR: ${error.toString()}');
  if (stackTrace != null) {
    logOutput('STACKTRACE: ${stackTrace.toString()}');
  }

  _crashReport(error, trace: stackTrace);
}