Skip to content
Snippets Groups Projects

bugfix(logger): memory consumption

Merged Grzegorz Rola requested to merge bugfix/memory-consumption into master

Files

+ 20
8
@@ -4,6 +4,7 @@ namespace WPDesk\ApiClient\Client;
@@ -4,6 +4,7 @@ namespace WPDesk\ApiClient\Client;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerInterface;
use Psr\Log\LoggerInterface;
 
use Psr\Log\NullLogger;
use WPDesk\HttpClient\HttpClient;
use WPDesk\HttpClient\HttpClient;
use WPDesk\HttpClient\HttpClientResponse;
use WPDesk\HttpClient\HttpClientResponse;
use WPDesk\ApiClient\Request\Request;
use WPDesk\ApiClient\Request\Request;
@@ -36,6 +37,9 @@ class ClientImplementation implements Client, LoggerAwareInterface
@@ -36,6 +37,9 @@ class ClientImplementation implements Client, LoggerAwareInterface
/** @var int */
/** @var int */
private $timeout;
private $timeout;
 
/** @var bool */
 
private $is_logger_available = false;
 
/**
/**
* Client constructor.
* Client constructor.
* @param HttpClient $client
* @param HttpClient $client
@@ -59,6 +63,7 @@ class ClientImplementation implements Client, LoggerAwareInterface
@@ -59,6 +63,7 @@ class ClientImplementation implements Client, LoggerAwareInterface
$this->apiUrl = $apiUri;
$this->apiUrl = $apiUri;
$this->defaultRequestHeaders = $defaultRequestHeaders;
$this->defaultRequestHeaders = $defaultRequestHeaders;
$this->timeout = $timeout;
$this->timeout = $timeout;
 
$this->is_logger_available = ! $logger instanceof NullLogger;
}
}
/**
/**
@@ -70,8 +75,10 @@ class ClientImplementation implements Client, LoggerAwareInterface
@@ -70,8 +75,10 @@ class ClientImplementation implements Client, LoggerAwareInterface
*/
*/
public function sendRequest(Request $request)
public function sendRequest(Request $request)
{
{
$this->logger->debug("Sends request with METHOD: {$request->getMethod()}; to ENDPOINT {$request->getEndpoint()}",
if ($this->is_logger_available) {
$this->getLoggerContext());
$this->logger->debug("Sends request with METHOD: {$request->getMethod()}; to ENDPOINT {$request->getEndpoint()}",
 
$this->getLoggerContext());
 
}
try {
try {
$httpResponse = $this->client->send(
$httpResponse = $this->client->send(
$fullUrl = $this->prepareFullUrl($request),
$fullUrl = $this->prepareFullUrl($request),
@@ -81,11 +88,16 @@ class ClientImplementation implements Client, LoggerAwareInterface
@@ -81,11 +88,16 @@ class ClientImplementation implements Client, LoggerAwareInterface
$this->timeout
$this->timeout
);
);
$this->logger->debug(
if ( $this->is_logger_available ) {
"Sent request with: URL: {$fullUrl};\n METHOD: {$method};\n BODY: {$body};\n"
$this->logger->debug(
. "HEADERS: " . json_encode($headers) . "\n\n and got response as CODE: {$httpResponse->getResponseCode()};\n"
"Sent request with: URL: {$fullUrl};\n METHOD: {$method};\n BODY: {$body};\n"
. "with RESPONSE BODY {$httpResponse->getBody()}",
."HEADERS: ".json_encode(
$this->getLoggerContext());
$headers
 
)."\n\n and got response as CODE: {$httpResponse->getResponseCode()};\n"
 
."with RESPONSE BODY {$httpResponse->getBody()}",
 
$this->getLoggerContext()
 
);
 
}
return $this->mapHttpResponseToApiResponse($httpResponse);
return $this->mapHttpResponseToApiResponse($httpResponse);
@@ -218,4 +230,4 @@ class ClientImplementation implements Client, LoggerAwareInterface
@@ -218,4 +230,4 @@ class ClientImplementation implements Client, LoggerAwareInterface
}
}
}
}
\ No newline at end of file
Loading