Skip to content

Commit

Permalink
Merge pull request #4 from dnna/master
Browse files Browse the repository at this point in the history
Make logs class configurable. Thanks to dnna.

This allows the Logs class to be defined via the configuration file. This will allow applications to implement custom logging mechanisms.
  • Loading branch information
Sergiusz Woźnicki committed Jan 17, 2014
2 parents f85699c + 500142a commit de7826e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
18 changes: 10 additions & 8 deletions MangoPaySDK/tools/restTool.inc
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,15 @@ class RestTool {
$this->_responseCode = (int)curl_getinfo($this->_curlHandle, CURLINFO_HTTP_CODE);

curl_close($this->_curlHandle);


$logClass = $this->_root->Config->LogClass;
if ($this->_root->Config->DebugMode)
Logs::Debug('Response JSON', $result);
$logClass::Debug('Response JSON', $result);

$response = json_decode($result);

if ($this->_root->Config->DebugMode)
Logs::Debug('Response object', $response);
$logClass::Debug('Response object', $response);

$this->CheckResponseCode($response);

Expand All @@ -138,8 +139,9 @@ class RestTool {
$restUrl = $urlTool->GetRestUrl($urlMethod, $this->_authRequired, $pagination, $additionalUrlParams);

$this->_requestUrl = $urlTool->GetFullUrl($restUrl);
$logClass = $this->_root->Config->LogClass;
if ($this->_root->Config->DebugMode)
Logs::Debug('FullUrl', $this->_requestUrl);
$logClass::Debug('FullUrl', $this->_requestUrl);

$this->_curlHandle = curl_init($this->_requestUrl);
if ($this->_curlHandle === false)
Expand All @@ -165,23 +167,23 @@ class RestTool {
}

if ($this->_root->Config->DebugMode)
Logs::Debug('RequestType', $this->_requestType);
$logClass::Debug('RequestType', $this->_requestType);

$httpHeaders = $this->GetHttpHeaders();
curl_setopt($this->_curlHandle, CURLOPT_HTTPHEADER, $httpHeaders);
if ($this->_root->Config->DebugMode)
Logs::Debug('HTTP Headers', $httpHeaders);
$logClass::Debug('HTTP Headers', $httpHeaders);

if (!is_null($this->_requestData)) {

if ($this->_root->Config->DebugMode)
Logs::Debug('RequestData object', $this->_requestData);
$logClass::Debug('RequestData object', $this->_requestData);

// encode to json if needed
if (in_array(self::$_JSON_HEADER, $httpHeaders)) {
$this->_requestData = json_encode($this->_requestData);
if ($this->_root->Config->DebugMode)
Logs::Debug('RequestData JSON', $this->_requestData);
$logClass::Debug('RequestData JSON', $this->_requestData);
}

curl_setopt($this->_curlHandle, CURLOPT_POSTFIELDS, $this->_requestData);
Expand Down
5 changes: 5 additions & 0 deletions MangoPaySDK/types/configuration.inc
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,9 @@ class Configuration {
* Switch debug mode: log all request and response data
*/
public $DebugMode = false;

/**
* Set the logging class if DebugMode is enabled
*/
public $LogClass = 'MangoPay\Logs';
}

0 comments on commit de7826e

Please sign in to comment.