Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug parsing response into header and body #523

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Request/response log message callback
Add a callback function to custom-handler request/response log messages.
ben-stonespot committed Dec 11, 2024
commit f80bf2cef27878df08867b9f6efcecbca3ceeea2
17 changes: 16 additions & 1 deletion src/DataService/DataService.php
Original file line number Diff line number Diff line change
@@ -270,7 +270,22 @@ public function setLogLocation($new_log_location)
return $this;
}

/**
/** (bch36)
* Set a callback function for request and response logs
*
* @param callable $callback The callback function for receiving request and response logs
*
* @return $this
*/
public function setLogCallback($callback)
{
$restHandler = $this->restHandler;
$loggerUsedByRestHandler = $restHandler->getRequestLogger();
$loggerUsedByRestHandler->setLogCallback($callback);
return $this;
}

/**
* Set logging for OAuth calls
*
* @param Boolean $enableLogs Turns on logging for OAuthCalls
34 changes: 25 additions & 9 deletions src/Diagnostics/LogRequestsToDisk.php
Original file line number Diff line number Diff line change
@@ -23,6 +23,12 @@ class LogRequestsToDisk
*/
public $ServiceRequestLoggingLocation;

/**
* The Service Request Logging Callback. (bch36)
* @var callable
*/
public $ServiceRequestLoggingCallback;

/**
* Initializes a new instance of the LogRequestsToDisk class.
* @param bool enableServiceRequestLogging Value indicating whether to log request response messages
@@ -50,6 +56,15 @@ public function setLogDirectory($logDirectory){
$this->ServiceRequestLoggingLocation = $logDirectory;
}

/** (bch36)
* Set a callback function for request and response logs
* @param callable $callback The callback function for receiving request and response logs
*/
public function setLogCallback($callback)
{
$this->ServiceRequestLoggingCallback = $callback;
}

/**
* Gets the log destination folder
* @return string log destination folder
@@ -104,15 +119,16 @@ public function LogPlatformRequests($xml, $url, $headers, $isRequest)
$collapsedHeaders[] = "{$key}: {$val}";
}

file_put_contents($filePath,
($isRequest?"REQUEST":"RESPONSE")." URI FOR SEQUENCE ID {$sequenceNumber}\n==================================\n{$url}\n\n",
FILE_APPEND);
file_put_contents($filePath,
($isRequest?"REQUEST":"RESPONSE")." HEADERS\n================\n".implode("\n", $collapsedHeaders)."\n\n",
FILE_APPEND);
file_put_contents($filePath,
($isRequest?"REQUEST":"RESPONSE")." BODY\n=============\n".$xml."\n\n",
FILE_APPEND);
$message =
($isRequest?"REQUEST":"RESPONSE")." URI FOR SEQUENCE ID {$sequenceNumber}\n==================================\n{$url}\n\n" .
($isRequest?"REQUEST":"RESPONSE")." HEADERS\n================\n".implode("\n", $collapsedHeaders)."\n\n" .
($isRequest?"REQUEST":"RESPONSE")." BODY\n=============\n".$xml."\n\n";

file_put_contents($filePath, $message);

if (is_callable($this->ServiceRequestLoggingCallback))
call_user_func($this->ServiceRequestLoggingCallback, $isRequest, $message, $url, $xml, $headers);

} catch (\Exception $e) {
throw new IdsException("Exception during LogPlatformRequests.");
}