diff --git a/composer.json b/composer.json index dfbbb9e..5a7d110 100644 --- a/composer.json +++ b/composer.json @@ -1,30 +1,31 @@ -{ - "name": "inwx/domrobot", - "description": "PHP Client to easily use the Domrobot API of INWX", - "license": "MIT", - "homepage": "https://www.inwx.com/en/", - "support": { - "docs": "https://www.inwx.com/en/help/apidoc", - "email": "support@inwx.de", - "source": "https://github.com/inwx/php-client" - }, - "authors": [ - { - "name": "INWX", - "email": "support@inwx.de" - } - ], - "require": { - "php": ">=7.2", - "ext-curl": "*" - }, - "autoload": { - "psr-4": { - "INWX\\": "src/" - } - }, - "suggest": { - "ext-xmlrpc": "Needed to use the XML-RPC API", - "ext-json": "Needed to use the JSON-RPC API" - } -} +{ + "name": "inwx/domrobot", + "description": "PHP Client to easily use the Domrobot API of INWX", + "license": "MIT", + "homepage": "https://www.inwx.com/en/", + "support": { + "docs": "https://www.inwx.com/en/help/apidoc", + "email": "support@inwx.de", + "source": "https://github.com/inwx/php-client" + }, + "authors": [ + { + "name": "INWX", + "email": "support@inwx.de" + } + ], + "require": { + "php": ">=7.2", + "ext-curl": "*", + "monolog/monolog": ">= 2.0.0" + }, + "autoload": { + "psr-4": { + "INWX\\": "src/" + } + }, + "suggest": { + "ext-xmlrpc": "Needed to use the XML-RPC API", + "ext-json": "Needed to use the JSON-RPC API" + } +} diff --git a/src/Domrobot.php b/src/Domrobot.php index 7868e9b..8cd0376 100644 --- a/src/Domrobot.php +++ b/src/Domrobot.php @@ -2,9 +2,13 @@ namespace INWX; +use Monolog\Handler\StreamHandler; +use Monolog\Logger; +use Psr\Log\LoggerAwareInterface; +use Psr\Log\LoggerInterface; use RuntimeException; -class Domrobot +class Domrobot implements LoggerAwareInterface { private const VERSION = '3.0'; private const LIVE_URL = 'https://api.domrobot.com/'; @@ -21,6 +25,11 @@ class Domrobot private $url = self::OTE_URL; private $api = self::JSONRPC; + /** + * @var LoggerInterface + */ + private $logger; + /** * Domrobot constructor. * @@ -28,6 +37,8 @@ class Domrobot */ public function __construct(?string $cookieFile = null) { + $this->logger = new Logger('domrobot_default_logger'); + $this->logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG)); $this->cookieFile = $cookieFile ?? tempnam(sys_get_temp_dir(), 'INWX'); } @@ -286,8 +297,8 @@ public function call(string $object, string $method, array $params = []): array $response = curl_exec($ch); curl_close($ch); if ($this->debug) { - echo "Request:\n" . $request . "\n"; - echo "Response:\n" . $response . "\n"; + $this->logger->debug("Request:\n" . $request . "\n"); + $this->logger->debug("Response:\n" . $response . "\n"); } if ($this->isJson()) { @@ -354,4 +365,12 @@ public function logout(): array return $ret; } + + /** + * @inheritDoc + */ + public function setLogger(LoggerInterface $logger) + { + $this->logger = $logger; + } }