Skip to content
This repository has been archived by the owner on Oct 22, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:cloudflare/cloudflare-plugin-backend
Browse files Browse the repository at this point in the history
  • Loading branch information
John Wineman committed Jun 14, 2016
2 parents 9f9d46b + 1cf580b commit 54f702b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 34 deletions.
21 changes: 17 additions & 4 deletions src/API/AbstractAPIClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,36 @@ public function callAPI(Request $request)
}

if (!$this->responseOk($response)) {
$this->logger->logAPICall($this->getAPIClientName(), array('type' => 'response', 'body' => $response), false);
$this->logAPICall($this->getAPIClientName(), array('type' => 'response', 'body' => $response), true);
}

return $response;
} catch (RequestException $e) {
$this->logger->logAPICall($this->getAPIClientName(), array(
$this->logAPICall($this->getAPIClientName(), array(
'type' => "request",
'method' => $request->getMethod(),
'path' => $request->getUrl(),
'headers' => $request->getHeaders(),
'params' => $request->getParameters(),
'body' => $request->getBody()), false);
$this->logger->logAPICall($this->getAPIClientName(), array('type' => "response", 'code' => $e->getCode(), 'body' => $e->getMessage(), 'stacktrace' => $e->getTraceAsString()), false);
'body' => $request->getBody()), true);
$this->logAPICall($this->getAPIClientName(), array('type' => "response", 'code' => $e->getCode(), 'body' => $e->getMessage(), 'stacktrace' => $e->getTraceAsString()), true);
return $this->createAPIError($e->getMessage());
}
}

public function logAPICall($api, $message, $isError) {
$logLevel = "error";
if ($isError === false) {
$logLevel = "debug";
}

if (!is_string($message)) {
$message = print_r($message, true);
}

$this->logger->$logLevel("[" . $api . "] " . $message);
}


/**
* @param Request $request
Expand Down
3 changes: 2 additions & 1 deletion src/Integration/DefaultIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace CF\Integration;

use \Psr\Log\LoggerInterface;

class DefaultIntegration implements IntegrationInterface
{
Expand All @@ -14,7 +15,7 @@ class DefaultIntegration implements IntegrationInterface
* @param ConfigInterface $config
* @param IntegrationAPIInterface $integrationAPI
* @param DataStoreInterface $dataStore
* @param LoggerInterface $logger
* @param LoggerInterface|\Psr\Log\LoggerInterface $logger
*/
public function __construct(ConfigInterface $config, IntegrationAPIInterface $integrationAPI, DataStoreInterface $dataStore, LoggerInterface $logger)
{
Expand Down
16 changes: 1 addition & 15 deletions src/Integration/DefaultLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use \Psr\Log\AbstractLogger;
use \Psr\Log\LogLevel;
use \Psr\Log\LoggerInterface;

class DefaultLogger extends AbstractLogger implements LoggerInterface
{
Expand Down Expand Up @@ -46,19 +47,4 @@ public function debug($message, array $context = array())
return $this->log(LogLevel::DEBUG, $message, $context);
}
}

public function logAPICall($api, $message, $is_debug)
{

$log_level = "error";
if ($is_debug) {
$log_level = "debug";
}

if (!is_string($message)) {
$message = print_r($message, true);
}

$this->$log_level("[" . $api . "] " . $message);
}
}
14 changes: 0 additions & 14 deletions src/Integration/LoggerInterface.php

This file was deleted.

0 comments on commit 54f702b

Please sign in to comment.