logRequest static method

void logRequest(
  1. RequestOptions requestOptions,
  2. List<LogOption> logOptions
)

Implementation

static void logRequest(
  RequestOptions requestOptions,
  List<LogOption> logOptions,
) {
  final messageBuffer = StringBuffer(
    '🌎 Request ║ ${requestOptions.method}\n',
  );
  messageBuffer.writeln(requestOptions.uri);
  messageBuffer.writeln();

  if (logOptions.contains(LogOption.requestHeaders)) {
    final requestHeaders = <String, dynamic>{};
    requestHeaders.addAll(requestOptions.headers);
    requestHeaders['responseType'] = requestOptions.responseType.toString();
    requestHeaders['followRedirects'] = requestOptions.followRedirects;
    requestHeaders['connectTimeout'] =
        requestOptions.connectTimeout?.toString();
    requestHeaders['receiveTimeout'] =
        requestOptions.receiveTimeout?.toString();

    messageBuffer.writeln(_getFromMap(requestHeaders, header: 'Headers:'));
  }

  if (logOptions.contains(LogOption.requestParameters) &&
      requestOptions.queryParameters.isNotEmpty) {
    messageBuffer.writeln('Query Parameters:');
    messageBuffer.writeln(
      _jsonEncoder.convert(requestOptions.queryParameters),
    );
    messageBuffer.writeln();
  }

  if (logOptions.contains(LogOption.requestBody) &&
      requestOptions.method != HTTPMethod.get.name) {
    messageBuffer.writeln(
      _getBody(
        key: 'Request Body',
        value: requestOptions.data,
      ),
    );
  }

  Log.d(messageBuffer);
}