machineRecordToValueTree function

Map<String, Object?> machineRecordToValueTree(
  1. Record record
)

Converts a v2 Record to the machine-consumer structured schema.

The returned tree always contains level, levelValue, UTC ISO-8601 time, message, and attrs. Optional name, error, stackTrace, caller, and structured isolate fields are present only when the record carries that metadata. Values are already normalized into the closed serializable set used by structured output.

The schema is stable-additive: existing fields keep their meanings, while compatible future releases may add optional fields that consumers ignore.

Implementation

Map<String, Object?> machineRecordToValueTree(Record record) => {
  'level': record.level.name,
  'levelValue': record.level.value,
  'time': record.time.toUtc().toIso8601String(),
  'message': record.message,
  if (record.name != null) 'name': record.name,
  'attrs': valueToTree(record.attrs),
  if (record.error != null) 'error': record.error.toString(),
  if (record.stackTrace != null) 'stackTrace': record.stackTrace.toString(),
  if (record.caller != null) 'caller': record.caller,
  if (record.isolate case final isolate?)
    'isolate': {
      'id': isolate.id,
      if (isolate.vmId != null) 'vmId': isolate.vmId,
      if (isolate.name != null) 'name': isolate.name,
    },
};