Skip to content

Commit

Permalink
Remove verbose logger option. Using NullLogger instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Gladyshev committed May 19, 2017
1 parent 7c51cdc commit 7e9df01
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
1.2.1 - Improve logger psr-3 support

1.2.0 - Add RecapthcaV2 methods

1.1.0 - Rename RucaptchaException to Exception
Expand Down
21 changes: 17 additions & 4 deletions src/GenericClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use Psr\Log\LoggerAwareInterface;
use Psr\Log\LoggerAwareTrait;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
use Rucaptcha\Exception\ErrorResponseException;
use Rucaptcha\Exception\InvalidArgumentException;
use Rucaptcha\Exception\Exception;
Expand Down Expand Up @@ -90,6 +91,18 @@ public function setHttpClient(ClientInterface $client)
return $this;
}

/**
* @param bool $verbose
* @return $this
*/
public function setVerbose($verbose)
{
$this->logger = null;
$this->verbose = $verbose;

return $this;
}

/**
* @param string $path
* @param array $extra
Expand Down Expand Up @@ -229,12 +242,12 @@ protected function getHttpClient()
/**
* @return LoggerInterface
*/
protected function getLogger()
public function getLogger()
{
if ($this->logger === null) {
$defaultLogger = new Logger;
$defaultLogger->verbose = & $this->verbose;

$defaultLogger = $this->verbose
? new Logger
: new NullLogger;
$this->setLogger($defaultLogger);
}
return $this->logger;
Expand Down
9 changes: 1 addition & 8 deletions src/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@

class Logger extends AbstractLogger
{
/**
* @var bool
*/
public $verbose = false;

/**
* @inheritDoc
*/
public function log($level, $message, array $context = [])
{
if ($this->verbose) {
echo date("d/m/y H:i:s", time()) . ' [' . $level . '] ' . $message . PHP_EOL;
}
echo date("d/m/y H:i:s", time()) . ' [' . $level . '] ' . $message . PHP_EOL;
}
}
12 changes: 0 additions & 12 deletions test/LoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,12 @@ class LoggerTest extends TestCase
public function testPrintingLogInStdOutIfVerboseFlag($level, $message)
{
$logger = new Logger;
$logger->verbose = true;

$logger->log($level, $message);

$this->expectOutputRegex("#\[{$level}\]\s{$message}#ui");
}

/**
* @dataProvider providerLevelMessages
*/
public function testDoNotPrintingInStdOutWithoutVerboseFlag($level, $message)
{
$logger = new Logger;
$logger->verbose = false;
$logger->log($level, $message);
$this->expectOutputString('');
}

public function providerLevelMessages()
{
return [
Expand Down

0 comments on commit 7e9df01

Please sign in to comment.