toDebugString method Null safety

String toDebugString(
  1. {bool includeElapsedTime = true,
  2. bool includeRequestIP = false,
  3. bool includeMethod = true,
  4. bool includeResource = true,
  5. bool includeStatusCode = true,
  6. bool includeContentSize = false,
  7. bool includeHeaders = false}
)

A string that represents more details about the request, typically used for logging.

Note: Setting includeRequestIP to true creates a significant performance penalty.

Implementation

String toDebugString({
  bool includeElapsedTime = true,
  bool includeRequestIP = false,
  bool includeMethod = true,
  bool includeResource = true,
  bool includeStatusCode = true,
  bool includeContentSize = false,
  bool includeHeaders = false,
}) {
  final builder = StringBuffer();
  if (includeRequestIP) {
    builder.write("${raw.connectionInfo?.remoteAddress.address} ");
  }
  if (includeMethod) {
    builder.write("${raw.method} ");
  }
  if (includeResource) {
    builder.write("${raw.uri} ");
  }
  if (includeElapsedTime && respondDate != null) {
    builder
        .write("${respondDate!.difference(receivedDate).inMilliseconds}ms ");
  }
  if (includeStatusCode) {
    builder.write("${raw.response.statusCode} ");
  }
  if (includeContentSize) {
    builder.write("${raw.response.contentLength} ");
  }
  if (includeHeaders) {
    builder.write("$_sanitizedHeaders ");
  }

  return builder.toString();
}