Skip to content

Commit

Permalink
refactor(dev options): rename output config option to log_payload
Browse files Browse the repository at this point in the history
Closes #453
  • Loading branch information
ArturMoczulski committed May 3, 2019
1 parent 4f96200 commit 8fac418
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 52 deletions.
53 changes: 26 additions & 27 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class Config
'include_error_code_context',
'include_exception_code_context',
'included_errno',
'output',
'output_logger',
'log_payload',
'log_payload_logger',
'person',
'person_fn',
'capture_ip',
Expand Down Expand Up @@ -85,19 +85,19 @@ class Config
private $transmit;

/**
* @var boolean $output If this is true then we output the payload to
* @var boolean $logPayload If this is true then we output the payload to
* standard out or a configured logger right before transmitting.
* Default: false
*/
private $output;
private $logPayload;

/**
* @var \Psr\Log\Logger $outputLogger Logger responsible for logging request
* @var \Psr\Log\Logger $logPayloadLogger Logger responsible for logging request
* payload and response dumps on. The messages logged can be controlled with
* `output` config options.
* `log_payload` config options.
* Default: \Monolog\Logger with \Monolog\Handler\ErrorLogHandler
*/
private $outputLogger;
private $logPayloadLogger;

/**
* @var string $verbose If this is set to any of the \Psr\Log\LogLevel options
Expand All @@ -107,7 +107,7 @@ class Config
* all the log levels of \Psr\Log\LogLevel
* (https://github.com/php-fig/log/blob/master/Psr/Log/LogLevel.php) plus
* an additional Rollbar\Config::VERBOSE_NONE option which makes the SDK quiet
* (excluding `output` option configured separetely).
* (excluding `log_payload` option configured separetely).
* Essentially this option controls the level of verbosity of the default
* `verbose_logger`. If you override the default `verbose_logger`, you need
* to implement obeying the `verbose` config option yourself.
Expand Down Expand Up @@ -278,8 +278,8 @@ protected function updateConfig($config)

$this->setEnabled($config);
$this->setTransmit($config);
$this->setOutput($config);
$this->setOutputLogger($config);
$this->setLogPayload($config);
$this->setLogPayloadLogger($config);
$this->setVerbose($config);
$this->setVerboseLogger($config);
$this->setAccessToken($config);
Expand Down Expand Up @@ -352,21 +352,21 @@ private function setTransmit($config)
\Rollbar\Defaults::get()->transmit();
}

private function setOutput($config)
private function setLogPayload($config)
{
$this->output = isset($config['output']) ?
$config['output'] :
\Rollbar\Defaults::get()->output();
$this->logPayload = isset($config['log_payload']) ?
$config['log_payload'] :
\Rollbar\Defaults::get()->logPayload();
}

private function setOutputLogger($config)
private function setLogPayloadLogger($config)
{
$this->outputLogger = isset($config['output_logger']) ?
$config['output_logger'] :
new \Monolog\Logger('rollbar.output', array(new \Monolog\Handler\ErrorLogHandler()));
$this->logPayloadLogger = isset($config['log_payload_logger']) ?
$config['log_payload_logger'] :
new \Monolog\Logger('rollbar.payload', array(new \Monolog\Handler\ErrorLogHandler()));

if (!($this->outputLogger instanceof \Psr\Log\LoggerInterface)) {
throw new \Exception('Output logger must implement \Psr\Log\LoggerInterface');
if (!($this->logPayloadLogger instanceof \Psr\Log\LoggerInterface)) {
throw new \Exception('Log Payload Logger must implement \Psr\Log\LoggerInterface');
}
}

Expand Down Expand Up @@ -529,9 +529,9 @@ public function transmitting()
return $this->transmit;
}

public function outputting()
public function loggingPayload()
{
return $this->output;
return $this->logPayload;
}

public function verbose()
Expand Down Expand Up @@ -713,9 +713,9 @@ protected function setupWithOptions(
}
}

public function outputLogger()
public function logPayloadLogger()
{
return $this->outputLogger;
return $this->logPayloadLogger;
}

public function verboseLogger()
Expand Down Expand Up @@ -1013,12 +1013,11 @@ public function send(EncodedPayload $payload, $accessToken)
$this->verboseLogger()->warning($response->getInfo());
}

if ($this->outputting()) {
$this->outputLogger()->debug(
if ($this->loggingPayload()) {
$this->logPayloadLogger()->debug(
'Sending payload with ' . get_class($this->sender) . ":\n" .
$payload
);
// $this->outputLogger()->debug($response);
}

return $response;
Expand Down
6 changes: 3 additions & 3 deletions src/Defaults.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,9 @@ public function transmit($value = null)
return $value !== null ? $value : $this->transmit;
}

public function output($value = null)
public function logPayload($value = null)
{
return $value !== null ? $value : $this->output;
return $value !== null ? $value : $this->logPayload;
}

public function verbose($value = null)
Expand Down Expand Up @@ -369,7 +369,7 @@ public function raiseOnError($value = null)
private $customDataMethod = null;
private $enabled = true;
private $transmit = true;
private $output = false;
private $logPayload = false;
private $verbose = \Rollbar\Config::VERBOSE_NONE;
private $environment = 'production';
private $fluentHost = '127.0.0.1';
Expand Down
28 changes: 14 additions & 14 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,26 +81,26 @@ public function testTransmit()
$this->assertFalse($config->transmitting());
}

public function testOutput()
public function testLogPayload()
{
$config = new Config(array(
'access_token' => $this->getTestAccessToken(),
'environment' => $this->env
));
$this->assertFalse($config->outputting());
$this->assertFalse($config->loggingPayload());

$config = new Config(array(
'access_token' => $this->getTestAccessToken(),
'environment' => $this->env,
'output' => true
'log_payload' => true
));
$this->assertTrue($config->outputting());
$this->assertTrue($config->loggingPayload());
}

public function testOutputting()
public function testLoggingPayload()
{
$outputLoggerMock = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock();
$outputLoggerMock->expects($this->once())
$logPayloadLoggerMock = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock();
$logPayloadLoggerMock->expects($this->once())
->method('debug')
->with(
$this->matchesRegularExpression(
Expand All @@ -117,31 +117,31 @@ public function testOutputting()
$config = new Config(array(
"access_token" => $this->getTestAccessToken(),
"environment" => "testing-php",
"output" => true,
"output_logger" => $outputLoggerMock,
"log_payload" => true,
"log_payload_logger" => $logPayloadLoggerMock,
"sender" => $senderMock
));
$config->send($payload, $this->getTestAccessToken());
}

public function testConfigureOutputLogger()
public function testConfigureLogPayloadLogger()
{
$config = new Config(array(
'access_token' => $this->getTestAccessToken(),
'environment' => $this->env
));
$this->assertInstanceOf('\Monolog\Logger', $config->outputLogger());
$handlers = $config->outputLogger()->getHandlers();
$this->assertInstanceOf('\Monolog\Logger', $config->logPayloadLogger());
$handlers = $config->logPayloadLogger()->getHandlers();
$handler = $handlers[0];
$this->assertInstanceOf('\Monolog\Handler\ErrorLogHandler', $handler);
$this->assertEquals(\Monolog\Logger::DEBUG, $handler->getLevel());

$config = new Config(array(
'access_token' => $this->getTestAccessToken(),
'environment' => $this->env,
'output_logger' => new \Psr\Log\NullLogger()
'log_payload_logger' => new \Psr\Log\NullLogger()
));
$this->assertInstanceOf('\Psr\Log\NullLogger', $config->outputLogger());
$this->assertInstanceOf('\Psr\Log\NullLogger', $config->logPayloadLogger());
}

public function testVerbose()
Expand Down
6 changes: 3 additions & 3 deletions tests/DefaultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,9 @@ public function testTransmit()
$this->assertTrue($this->defaults->transmit());
}

public function testOutput()
public function testLogPayload()
{
$this->assertFalse($this->defaults->output());
$this->assertFalse($this->defaults->logPayload());
}

public function testEnvironment()
Expand Down Expand Up @@ -278,7 +278,7 @@ public function testDefaultsForConfigOptions()
$option == 'proxy' ||
$option == 'include_raw_request_body' ||
$option == 'verbose_logger' ||
$option == 'output_logger') {
$option == 'log_payload_logger') {
continue;
} elseif ($option == 'base_api_url') {
$option = 'endpoint';
Expand Down
10 changes: 5 additions & 5 deletions tests/RollbarLoggerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,16 @@ public function testLog()
$this->assertEquals(200, $response->getStatus());
}

public function testNotOutputting()
public function testNotLoggingPayload()
{
$outputLoggerMock = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock();
$outputLoggerMock->expects($this->never())->method('debug');
$logPayloadLoggerMock = $this->getMockBuilder('\Psr\Log\LoggerInterface')->getMock();
$logPayloadLoggerMock->expects($this->never())->method('debug');

$logger = new RollbarLogger(array(
"access_token" => $this->getTestAccessToken(),
"environment" => "testing-php",
"output" => false,
"outputLogger" => $outputLoggerMock
"log_payload" => false,
"log_payload_logger" => $logPayloadLoggerMock
));
$response = $logger->log(Level::WARNING, "Testing PHP Notifier");

Expand Down

0 comments on commit 8fac418

Please sign in to comment.