Skip to content

Commit

Permalink
Aggiunto logging di tutte le richieste
Browse files Browse the repository at this point in the history
  • Loading branch information
HighLiuk committed Sep 23, 2021
1 parent 4f1cc5e commit a5c7374
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
use GuzzleHttp\Handler\CurlHandler;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\Middleware;
use GuzzleHttp\MessageFormatter;
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use GuzzleHttp\Exception\RequestException;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Exception;
use Throwable;

Expand Down Expand Up @@ -165,12 +168,30 @@ public function getEventTrackingActid()
*/
public function withRetry(int $retry_times = 10, float $retry_delay = 0.5)
{
// Imposta il retry automatico
$handlerStack = HandlerStack::create(new CurlHandler());

$logger = new Logger('Guzzle');
$logger->pushHandler(
new StreamHandler(storage_path(
'logs' . DIRECTORY_SEPARATOR . 'guzzle-' . date('Y-m-d') . '.log'
)),
Logger::DEBUG
);

// Logga tutte le richieste
$handlerStack->push(Middleware::log(
$logger,
new MessageFormatter(
'{method} {uri} HTTP/{version} {req_body} RESPONSE: {code} - {res_body}'
)
));

// Imposta il retry automatico
$handlerStack->push(Middleware::retry(
$this->retryDecider($retry_times),
$this->retryDelay($retry_delay)
));

$this->options['handler'] = $handlerStack;

$this->client = new \GuzzleHttp\Client($this->options);
Expand Down

0 comments on commit a5c7374

Please sign in to comment.