logRequest method

void logRequest(
  1. RequestOptions options, {
  2. DateTime? startTime,
})

Log request details

Implementation

void logRequest(RequestOptions options, {DateTime? startTime}) {
  if (!enabled) return;
  final uri = options.uri;
  final method = options.method.toUpperCase();
  final headers = options.headers;
  final data = options.data;
  final queryParameters = options.queryParameters;

  _outputLine('\n$_cyan┌${'─' * 58}┐$_reset');
  _outputLine(
    '$_cyan│$_bold$_cyan📤 API REQUEST$_reset $_bold$_yellow[${_formatDateTime(startTime ?? DateTime.now())}]$_reset$_cyan│$_reset',
  );
  _outputLine('$_cyan└${'─' * 58}┘$_reset');

  // Method and URL
  _outputLine('$_bold${_blue}Method:$_reset $method');
  _outputLine('$_bold${_magenta}URL:$_reset $uri');

  // Headers (with token display - full for debugging, but masked in production if needed)
  if (headers.isNotEmpty) {
    _outputLine('\n$_yellow📋 Headers:$_reset');
    headers.forEach((key, value) {
      final displayValue = _maskSensitiveHeader(key, value.toString());
      _outputLine('  $_bold$key:$_reset $displayValue');
    });
  }

  // Query Parameters
  if (queryParameters.isNotEmpty) {
    _outputLine('\n$_yellow🔍 Query Parameters:$_reset');
    queryParameters.forEach((key, value) {
      _outputLine('  $_bold$key:$_reset $value');
    });
  }

  // Request Body
  if (data != null) {
    _outputLine('\n$_yellow📦 Request Body:$_reset');
    if (data is FormData) {
      _logFormData(data);
    } else if (data is Map || data is List) {
      try {
        final prettyJson = JsonEncoder.withIndent('  ').convert(data);
        _outputPrettyJson(prettyJson);
      } catch (e) {
        _outputLine(data.toString());
      }
    } else {
      _outputLine(data.toString());
    }
  }

  _outputLine('$_cyan└${'─' * 60}┘$_reset');
}