From 2943e4d9581cb41336475ac707774c9273cff9db Mon Sep 17 00:00:00 2001 From: hlu2 Date: Tue, 19 Jun 2018 17:25:27 -0700 Subject: [PATCH] Fix logging disable issue --- src/Core/HttpClients/SyncRestHandler.php | 8 ++++++++ src/DataService/DataService.php | 26 ++++++++++++++++++------ src/Diagnostics/LogRequestsToDisk.php | 18 +++++++++++++++- 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/Core/HttpClients/SyncRestHandler.php b/src/Core/HttpClients/SyncRestHandler.php index b27aba81..38ff2e98 100644 --- a/src/Core/HttpClients/SyncRestHandler.php +++ b/src/Core/HttpClients/SyncRestHandler.php @@ -82,6 +82,14 @@ public function updateContext($newServiceContext){ } } + /** + * Return the RequestLogger + * @return LogRequestsToDisk $requestLogger; + */ + public function getRequestLogger(){ + return $this->RequestLogging; + } + /** * Return an representation of an error returned by the last request, or false if the last request was not an error. diff --git a/src/DataService/DataService.php b/src/DataService/DataService.php index 54e3bc18..ca035e82 100644 --- a/src/DataService/DataService.php +++ b/src/DataService/DataService.php @@ -259,9 +259,9 @@ public function useJson() */ public function setLogLocation($new_log_location) { - $serviceContext = $this->getServiceContext(); - $serviceContext->setLogLocation($new_log_location); - $this->updateServiceContextSettingsForOthers($serviceContext); + $restHandler = $this->restHandler; + $loggerUsedByRestHandler = $restHandler->getRequestLogger(); + $loggerUsedByRestHandler->setLogDirectory($new_log_location); return $this; } @@ -287,9 +287,22 @@ public function setMinorVersion($newMinorVersion) */ public function disableLog() { - $serviceContext = $this->getServiceContext(); - $serviceContext->disableLog(); - $this->updateServiceContextSettingsForOthers($serviceContext); + $restHandler = $this->restHandler; + $loggerUsedByRestHandler = $restHandler->getRequestLogger(); + $loggerUsedByRestHandler->setLogStatus(false); + return $this; + } + + /** + * Enable the logging function + * + * @return $this + */ + public function enableLog() + { + $restHandler = $this->restHandler; + $loggerUsedByRestHandler = $restHandler->getRequestLogger(); + $loggerUsedByRestHandler->setLogStatus(true); return $this; } @@ -300,6 +313,7 @@ public function disableLog() */ public function throwExceptionOnError($bool){ $this->throwExceptionOnError = $bool; + return $this; } /** diff --git a/src/Diagnostics/LogRequestsToDisk.php b/src/Diagnostics/LogRequestsToDisk.php index 7c1bf45b..4100ecd8 100644 --- a/src/Diagnostics/LogRequestsToDisk.php +++ b/src/Diagnostics/LogRequestsToDisk.php @@ -30,10 +30,26 @@ class LogRequestsToDisk */ public function __construct($enableServiceRequestLogging=false, $serviceRequestLoggingLocation=null) { - $this->EnableServiceRequestsLogging = (!empty($enableServiceRequestLogging) && ("false" !== strtolower(trim($enableServiceRequestLogging)))); + $this->EnableServiceRequestsLogging = $enableServiceRequestLogging; $this->ServiceRequestLoggingLocation = $serviceRequestLoggingLocation; } + /** + * Enabled or disable the log + * @param Boolean $status + */ + public function setLogStatus($status){ + $this->EnableServiceRequestsLogging = $status; + } + + /** + * Set Log directory + * @param String $logDirectory + */ + public function setLogDirectory($logDirectory){ + $this->ServiceRequestLoggingLocation = $logDirectory; + } + /** * Gets the log destination folder * @return string log destination folder