upsertLog method

void upsertLog(
  1. String transactionId,
  2. Map<String, dynamic> logUpdate
)

Add or update a log entry for a transaction.

Implementation

void upsertLog(String transactionId, Map<String, dynamic> logUpdate) {
  if (!NetworkLoggerConfig.isEnabled) {
    return;
  }
  try {
    final existing = _logs[transactionId] ?? {};
    final merged = {
      ...existing,
      ...logUpdate,
      'transactionId': transactionId,
    };
    _logs[transactionId] = merged;
    if (!_logOrder.contains(transactionId)) {
      _logOrder.addLast(transactionId);
    }
    // Remove old entries if we exceed the limit
    while (_logOrder.length > NetworkLoggerConfig.maxLogEntries) {
      final removedId = _logOrder.removeFirst();
      _logs.remove(removedId);
    }
    NetworkLogWebServer.instance.broadcastLog(merged);
  } catch (e) {
    if (kDebugMode) debugPrint('❌ NetworkLogStore: Failed to upsert log: $e');
  }
}