sanitizeSintLogMessage function

  1. @visibleForTesting
String sanitizeSintLogMessage(
  1. String raw, {
  2. int maxChars = 2000,
})

Redacts query-string tokens, inline API credentials, Gemma-4 reasoning blocks, and Bidi/C0-C1 controls before emitting framework logs.

Implementation

@visibleForTesting
String sanitizeSintLogMessage(String raw, {int maxChars = 2000}) {
  final safeCap = maxChars.isFinite ? maxChars : 2000;
  if (safeCap <= 0) return '';
  final cleaned = raw
      .replaceAll(_kSintLogInternalTags, '')
      .replaceAllMapped(_kSintLogUrlBasicAuth, (m) => '${m[1]}[REDACTED]@')
      .replaceAllMapped(_kSintLogSecretQuery, (m) => '${m[1]}REDACTED')
      .replaceAll(_kSintLogInlineToken, '[REDACTED]')
      .replaceAll(_kSintLogControlsAndBidi, '');
  if (cleaned.length <= safeCap) return cleaned;
  var end = safeCap;
  final lastCode = cleaned.codeUnitAt(end - 1);
  if (lastCode >= 0xD800 && lastCode <= 0xDBFF) end--;
  return end <= 0 ? '' : cleaned.substring(0, end);
}