-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(dev options): add verbose and verbose_logger
Closes re #453
- Loading branch information
1 parent
46730f3
commit 92782a3
Showing
6 changed files
with
168 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* \Rollbar\VerboseLogger is a class used as the internal verbosity logger | ||
* for the SDK. A custom class was needed to support level | ||
* \Rollbar\Config::VERBOSE_NONE in the `verbose` config option which | ||
* makes the logger completely quiet. | ||
* | ||
* Using this logger, if the SDK is configured with | ||
* `verbose` == \Rollbar\Config::VERBOSE_NONE any logging calls like | ||
* $verboseLogger->info("Message") will be ignored. | ||
* | ||
* @package \Rollbar | ||
* @author Artur Moczulski <[email protected]> | ||
* @author Rollbar, Inc. | ||
*/ | ||
namespace Rollbar; | ||
|
||
class VerboseLogger extends \Monolog\Logger | ||
{ | ||
private $config; | ||
|
||
public function __construct($name, $rollbarConfig, array $handlers = array(), array $processors = array()) | ||
{ | ||
$this->config = $rollbarConfig; | ||
parent::__construct($name, $handlers, $processors); | ||
} | ||
|
||
/** | ||
* Adds a log record at an arbitrary level. | ||
* | ||
* @param mixed $level The log level. Supported log level are | ||
* \Psr\Log\LogLevel plus \Rollbar\Config::VERBOSE_NONE | ||
* @param string $message The log message | ||
* @param array $context The log context | ||
* @return bool Whether the record has been processed | ||
*/ | ||
public function addRecord($level, $message, array $context = array()) | ||
{ | ||
if ($this->config->verbose() == Config::VERBOSE_NONE) { | ||
return false; | ||
} | ||
|
||
return parent::addRecord($level, $message, $context); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php namespace Rollbar; | ||
|
||
use \Mockery as m; | ||
|
||
class VerboseLoggerTest extends BaseRollbarTest | ||
{ | ||
public function testLog() | ||
{ | ||
// verbose == VERBOSE_NONE | ||
$config = new Config(array( | ||
'access_token' => $this->getTestAccessToken(), | ||
'environment' => "test", | ||
'verbose' => Config::VERBOSE_NONE | ||
)); | ||
$handler = m::mock('\Monolog\Handler\AbstractHandler')->makePartial(); | ||
$handler->shouldNotReceive('handle'); | ||
$subject = new VerboseLogger('verbose', $config, array($handler)); | ||
$this->assertFalse($subject->info("test log")); | ||
|
||
// verbose == INFO | ||
$handler->shouldReceive('handle'); | ||
$config->configure(array('verbose' => \Psr\Log\LogLevel::INFO)); | ||
$this->assertTrue($subject->info("test log")); | ||
} | ||
} |