Skip to content

Commit 79fec31

Browse files
committed
Lets Domrobot implement LoggerAwareInterface. Sets default logger log to stdout
1 parent b0b1bd9 commit 79fec31

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/Domrobot.php

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
namespace INWX;
44

5+
use Monolog\Handler\StreamHandler;
6+
use Monolog\Logger;
7+
use Psr\Log\LoggerAwareInterface;
8+
use Psr\Log\LoggerInterface;
59
use RuntimeException;
610

7-
class Domrobot
11+
class Domrobot implements LoggerAwareInterface
812
{
913
private const VERSION = '3.0';
1014
private const LIVE_URL = 'https://api.domrobot.com/';
@@ -21,13 +25,20 @@ class Domrobot
2125
private $url = self::OTE_URL;
2226
private $api = self::JSONRPC;
2327

28+
/**
29+
* @var LoggerInterface
30+
*/
31+
private $logger;
32+
2433
/**
2534
* Domrobot constructor.
2635
*
2736
* @param string|null $cookieFile You can overwrite the standard cookieFile path by setting a full path here
2837
*/
2938
public function __construct(?string $cookieFile = null)
3039
{
40+
$this->logger = new Logger('domrobot_default_logger');
41+
$this->logger->pushHandler(new StreamHandler('php://stdout', Logger::DEBUG));
3142
$this->cookieFile = $cookieFile ?? tempnam(sys_get_temp_dir(), 'INWX');
3243
}
3344

@@ -286,8 +297,8 @@ public function call(string $object, string $method, array $params = []): array
286297
$response = curl_exec($ch);
287298
curl_close($ch);
288299
if ($this->debug) {
289-
echo "Request:\n" . $request . "\n";
290-
echo "Response:\n" . $response . "\n";
300+
$this->logger->debug("Request:\n" . $request . "\n");
301+
$this->logger->debug("Response:\n" . $response . "\n");
291302
}
292303

293304
if ($this->isJson()) {
@@ -354,4 +365,12 @@ public function logout(): array
354365

355366
return $ret;
356367
}
368+
369+
/**
370+
* @inheritDoc
371+
*/
372+
public function setLogger(LoggerInterface $logger)
373+
{
374+
$this->logger = $logger;
375+
}
357376
}

0 commit comments

Comments
 (0)