Skip to content

Commit

Permalink
Create logger instance with method
Browse files Browse the repository at this point in the history
  • Loading branch information
kg-bot committed Mar 27, 2020
1 parent 54d87aa commit 43a49a3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 46 deletions.
42 changes: 0 additions & 42 deletions src/Utils/GuzzleLoggerInstance.php

This file was deleted.

23 changes: 19 additions & 4 deletions src/Utils/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\ServerException;
use GuzzleHttp\HandlerStack;
use GuzzleHttp\MessageFormatter;
use GuzzleHttp\Middleware;
use Illuminate\Support\Facades\Config;
use Monolog\Handler\StreamHandler;
use Monolog\Logger;
use Rackbeat\Exceptions\RackbeatClientException;
use Rackbeat\Exceptions\RackbeatRequestException;
use Spatie\GuzzleRateLimiterMiddleware\RateLimiterMiddleware;
Expand Down Expand Up @@ -110,9 +114,20 @@ public function createThrottleMiddleware()

public function createLoggerMiddleware($log_path = null)
{
$logger = new GuzzleLoggerInstance($log_path);

return $logger->getStack();
$log_path = $log_path ?? 'guzzle-logger.log';

$logger = new Logger('GuzzleCustomLogger');
$location = storage_path('logs/' . $log_path);
$logger->pushHandler(new StreamHandler($location, Logger::DEBUG));

$format =
'{method} {uri} - {target} - {hostname} HTTP/{version} .......... ' .
'REQUEST HEADERS: {req_headers} ....... REQUEST: {req_body} ' .
'......... RESPONSE HEADERS: {res_headers} ........... RESPONSE: {code} - {res_body}';
return Middleware::log(
$logger,
new MessageFormatter($format)
);
}

public function addCustomMiddlewares(array $options, $log, $log_path)
Expand All @@ -128,7 +143,7 @@ public function addCustomMiddlewares(array $options, $log, $log_path)

if ($log) {

$options['handler']->push((new GuzzleLoggerInstance($log_path))->getStack());
$options['handler']->push($this->createLoggerMiddleware($log_path));
}

return $options;
Expand Down

0 comments on commit 43a49a3

Please sign in to comment.