Skip to content

Commit

Permalink
Fix logging of response errors
Browse files Browse the repository at this point in the history
Two things were incorrect previously:

- Logging was at Debug and Info, raised to Warning so it shows in logs by default
- Body and responseBody were not being passed to the logging method correctly

Related to #95
  • Loading branch information
polyfractal committed Jun 18, 2014
1 parent 8dace3f commit 7d91545
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/Elasticsearch/Connections/AbstractConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,8 @@ public function logRequestFail(
$exception = null
) {
$this->log->debug('Request Body', array($body));
$this->log->info(
'Request Success:',
$this->log->warning(
'Request Failure:',
array(
'method' => $method,
'uri' => $fullURI,
Expand All @@ -186,7 +186,7 @@ public function logRequestFail(
'error' => $exception,
)
);
$this->log->debug('Response', array($response));
$this->log->warning('Response', array($response));

// Build the curl command for Trace.
$curlCommand = $this->buildCurlCommand($method, $fullURI, $body);
Expand Down
20 changes: 11 additions & 9 deletions src/Elasticsearch/Connections/CurlMultiConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,9 +207,9 @@ public function performRequest($method, $uri, $params = null, $body = null, $opt
}

if ($response['requestInfo']['http_code'] >= 400 && $response['requestInfo']['http_code'] < 500) {
$this->process4xxError($method, $uri, $response);
$this->process4xxError($method, $uri, $body, $response);
} else if ($response['requestInfo']['http_code'] >= 500) {
$this->process5xxError($method, $uri, $response);
$this->process5xxError($method, $uri, $body, $response);
}

$this->lastRequest['response']['body'] = $response['responseText'];
Expand Down Expand Up @@ -257,9 +257,9 @@ public function getLastRequestInfo()
* @throws \Elasticsearch\Common\Exceptions\Missing404Exception
* @throws \Elasticsearch\Common\Exceptions\AlreadyExpiredException
*/
private function process4xxError($method, $uri, $response)
private function process4xxError($method, $uri, $request, $response)
{
$this->logErrorDueToFailure($method, $uri, $response);
$this->logErrorDueToFailure($method, $uri, $request, $response);

$statusCode = $response['requestInfo']['http_code'];
$exceptionText = $response['error'];
Expand Down Expand Up @@ -293,9 +293,9 @@ private function process4xxError($method, $uri, $response)
* @throws \Elasticsearch\Common\Exceptions\NoDocumentsToGetException
* @throws \Elasticsearch\Common\Exceptions\ServerErrorResponseException
*/
private function process5xxError($method, $uri, $response)
private function process5xxError($method, $uri, $request, $response)
{
$this->logErrorDueToFailure($method, $uri, $response);
$this->logErrorDueToFailure($method, $uri, $request, $response);

$statusCode = $response['requestInfo']['http_code'];
$exceptionText = $response['error'];
Expand Down Expand Up @@ -334,17 +334,19 @@ private function processCurlError($method, $uri, $response)
/**
* @param $method
* @param $uri
* @param $request
* @param $response
*/
private function logErrorDueToFailure($method, $uri, $response)
private function logErrorDueToFailure($method, $uri, $request, $response)
{
$this->logRequestFail(
$method,
$uri,
$response['requestInfo']['total_time'],
$request,
$response['requestInfo']['http_code'],
$response['responseText'],
$response['error']
$response['error'],
$response
);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Elasticsearch/Connections/GuzzleConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,10 +288,10 @@ private function logErrorDueToFailure(Request $request, \Exception $exception, $
$this->logRequestFail(
$request->getMethod(),
$request->getUrl(),
$response->getInfo('total_time'),
$body,
$headers,
$response->getStatusCode(),
$body,
$responseBody,
$exception->getMessage()
);
}
Expand Down

0 comments on commit 7d91545

Please sign in to comment.