logResponse static method

void logResponse(
  1. Response response,
  2. List<LogOption> logOptions
)

Implementation

static void logResponse(
  Response response,
  List<LogOption> logOptions,
) {
  final method = response.requestOptions.method;
  final uri = response.requestOptions.uri;
  final messageBuffer = StringBuffer(
    '👍 Response ║ $method ║ Status: ${response.statusCode} ${response.statusMessage}\n',
  );
  messageBuffer.writeln(uri);
  messageBuffer.writeln();

  if (logOptions.contains(LogOption.responseHeaders)) {
    final requestHeaders = response.headers.map;
    messageBuffer.writeln(_getFromMap(requestHeaders, header: 'Headers:'));
  }

  if (logOptions.contains(LogOption.responseData)) {
    messageBuffer.writeln(
      _getBody(
        key: 'Response Body:',
        value: response.data,
        isResponse: true,
      ),
    );
  }

  Log.d(messageBuffer);
}