Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to config minimumLevel option. #440

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 21 additions & 15 deletions src/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class Config
'include_raw_request_body',
'local_vars_dump',
'max_nesting_depth',
'max_items'
'max_items',
'monolog_minimum_level'
);

private $accessToken;
Expand Down Expand Up @@ -88,7 +89,7 @@ class Config
* @var FilterInterface
*/
private $filter;
private $minimumLevel;
private $monologMinimumLevel;
/**
* @var ResponseHandlerInterface
*/
Expand Down Expand Up @@ -209,7 +210,7 @@ protected function updateConfig($config)
$this->setAccessToken($config);
$this->setDataBuilder($config);
$this->setTransformer($config);
$this->setMinimumLevel($config);
$this->setMonologMinimumLevel($config);
$this->setReportSuppressed($config);
$this->setFilters($config);
$this->setSender($config);
Expand Down Expand Up @@ -299,20 +300,20 @@ private function setTransformer($config)
$this->setupWithOptions($config, "transformer", $expected);
}

private function setMinimumLevel($config)
private function setMonologMinimumLevel($config)
{
$this->minimumLevel = 0;
if (empty($config['minimumLevel'])) {
$this->minimumLevel = 0;
} elseif ($config['minimumLevel'] instanceof Level) {
$this->minimumLevel = $config['minimumLevel']->toInt();
} elseif (is_string($config['minimumLevel'])) {
$level = $this->levelFactory->fromName($config['minimumLevel']);
$this->monologMinimumLevel = 0;
if (empty($config['monologMinimumLevel'])) {
$this->monologMinimumLevel = 0;
} elseif ($config['monologMinimumLevel'] instanceof Level) {
$this->monologMinimumLevel = $config['monologMinimumLevel']->toInt();
} elseif (is_string($config['monologMinimumLevel'])) {
$level = $this->levelFactory->fromName($config['monologMinimumLevel']);
if ($level !== null) {
$this->minimumLevel = $level->toInt();
$this->monologMinimumLevel = $level->toInt();
}
} elseif (is_int($config['minimumLevel'])) {
$this->minimumLevel = $config['minimumLevel'];
} elseif (is_int($config['monologMinimumLevel'])) {
$this->monologMinimumLevel = $config['monologMinimumLevel'];
}
}

Expand Down Expand Up @@ -600,6 +601,11 @@ public function getMaxItems()
return $this->maxItems;
}

public function getMonologMinimumLevel()
{
return $this->monologMinimumLevel;
}

/**
* @param Payload $payload
* @param Level $level
Expand Down Expand Up @@ -802,7 +808,7 @@ private function payloadLevelTooLow($payload)
*/
private function levelTooLow($level)
{
return $level->toInt() < $this->minimumLevel;
return $level->toInt() < $this->monologMinimumLevel;
}

private function shouldSuppress()
Expand Down
8 changes: 7 additions & 1 deletion src/Defaults.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php namespace Rollbar;

use Rollbar\Utilities;
use Monolog\Logger;
use Rollbar\Payload\Notifier;
use Psr\Log\LogLevel;

Expand Down Expand Up @@ -313,6 +313,11 @@ public function maxItems($value = null)
return $value !== null ? $value : $this->maxItems;
}

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

private $psrLevels;
private $errorLevels;
private $autodetectBranch = false;
Expand Down Expand Up @@ -358,4 +363,5 @@ public function maxItems($value = null)
private $scrubFields;
private $customTruncation = null;
private $maxItems = 10;
private $monologMinimumLevel = Logger::ERROR;
}
12 changes: 6 additions & 6 deletions tests/ConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,19 @@ public function testTransformer()
$this->assertEquals($pPrime, $config->transform($p, "error", "message", "extra_data"));
}

public function testMinimumLevel()
public function testMonologMinimumLevel()
{
$c = new Config(array(
"access_token" => $this->getTestAccessToken(),
"environment" => $this->env,
"minimumLevel" => "warning"
'access_token' => $this->getTestAccessToken(),
'environment' => $this->env,
'monologMinimumLevel' => 'warning'
));
$this->runConfigTest($c);

$c->configure(array("minimumLevel" => Level::WARNING));
$c->configure(array('monologMinimumLevel' => Level::WARNING));
$this->runConfigTest($c);

$c->configure(array("minimumLevel" => Level::WARNING()->toInt()));
$c->configure(array('monologMinimumLevel' => Level::WARNING()->toInt()));
$this->runConfigTest($c);
}

Expand Down