diff --git a/src/Core/HttpClients/CurlHttpClient.php b/src/Core/HttpClients/CurlHttpClient.php index f5c66634..a4e0dbde 100644 --- a/src/Core/HttpClients/CurlHttpClient.php +++ b/src/Core/HttpClients/CurlHttpClient.php @@ -118,8 +118,8 @@ private function handleErrors(){ */ public function setIntuitResponse($response){ $headerSize = $this->basecURL->getInfo(CURLINFO_HEADER_SIZE); - $rawHeaders = mb_substr($response, 0, $headerSize); - $rawBody = mb_substr($response, $headerSize); + $rawHeaders = substr($response, 0, $headerSize); + $rawBody = substr($response, $headerSize); $httpStatusCode = $this->basecURL->getInfo(CURLINFO_HTTP_CODE); $theIntuitResponse = new IntuitResponse($rawHeaders, $rawBody, $httpStatusCode, true); $this->intuitResponse = $theIntuitResponse; diff --git a/src/DataService/DataService.php b/src/DataService/DataService.php index 688ab41b..de31cf2b 100644 --- a/src/DataService/DataService.php +++ b/src/DataService/DataService.php @@ -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 diff --git a/src/Diagnostics/LogRequestsToDisk.php b/src/Diagnostics/LogRequestsToDisk.php index 4100ecd8..25cd4f0c 100644 --- a/src/Diagnostics/LogRequestsToDisk.php +++ b/src/Diagnostics/LogRequestsToDisk.php @@ -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."); }