Skip to content

Commit

Permalink
Merge pull request #691 from colinmollenhour/patch-1
Browse files Browse the repository at this point in the history
Simplify logging of exceptions, requests and responses.
  • Loading branch information
jlevers authored Apr 23, 2024
2 parents 8b819f7 + 1d38ef8 commit 5b985df
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jlevers/selling-partner-api",
"version": "5.10.2",
"version": "5.10.3",
"description": "PHP client for Amazon's Selling Partner API",
"keywords": [
"api",
Expand Down
11 changes: 10 additions & 1 deletion lib/Api/BaseApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,18 @@ protected function createHttpClientOption()
protected function writeDebug($data)
{
if ($this->config->getDebug()) {
if ($data instanceof Throwable) {
$data = "$data";
} else if ($data instanceof GuzzleHttp\Psr7\Request) {
$data = "{$data->getMethod()} {$data->getUri()}\n" . implode("\n", $data->getHeaders());
} else if ($data instanceof GuzzleHttp\Psr7\Response) {
$data = "{$data->getStatusCode()} {$data->getReasonPhrase()}\n" . implode("\n", $data->getHeaders());
} else {
$data = print_r($data, true);
}
file_put_contents(
$this->config->getDebugFile(),
'[' . date('Y-m-d H:i:s') . ']: ' . print_r($data, true) . "\n",
'[' . date('Y-m-d H:i:s') . ']: ' . $data . "\n",
FILE_APPEND
);
}
Expand Down
4 changes: 2 additions & 2 deletions lib/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Configuration
*
* @var string
*/
protected $userAgent = 'jlevers/selling-partner-api/5.10.2 (Language=PHP)';
protected $userAgent = 'jlevers/selling-partner-api/5.10.3 (Language=PHP)';

/**
* Debug switch (default set to false)
Expand Down Expand Up @@ -429,7 +429,7 @@ public static function toDebugReport(?string $tempFolderPath = null)
$report .= ' OS: ' . php_uname() . PHP_EOL;
$report .= ' PHP Version: ' . PHP_VERSION . PHP_EOL;
$report .= ' The version of the OpenAPI document: 2020-11-01' . PHP_EOL;
$report .= ' SDK Package Version: 5.10.2' . PHP_EOL;
$report .= ' SDK Package Version: 5.10.3' . PHP_EOL;
$report .= ' Temp Folder Path: ' . $tempFolderPath . PHP_EOL;

return $report;
Expand Down

0 comments on commit 5b985df

Please sign in to comment.