diff --git a/src/Utils/GuzzleLoggerInstance.php b/src/Utils/GuzzleLoggerInstance.php deleted file mode 100755 index 9fa2bc5..0000000 --- a/src/Utils/GuzzleLoggerInstance.php +++ /dev/null @@ -1,42 +0,0 @@ -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}'; - $stack = HandlerStack::create(); - $stack->push( - Middleware::log( - $logger, - new MessageFormatter($format) - ) - ); - - $this->stack = $stack; - } - - public function getStack() - { - return $this->stack; - } -} diff --git a/src/Utils/Request.php b/src/Utils/Request.php index 5b02424..a4e9bae 100644 --- a/src/Utils/Request.php +++ b/src/Utils/Request.php @@ -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; @@ -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) @@ -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;