Skip to content

Add listen new config param "minimum_level" error log. #44

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

Closed
Closed
Changes from 1 commit
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
45 changes: 23 additions & 22 deletions Factories/RollbarHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@
*/
class RollbarHandlerFactory
{
/**
* @var string|null
*/
private $minimumLevel;

/**
* RollbarHandlerFactory constructor.
*
Expand All @@ -30,30 +35,26 @@ public function __construct(ContainerInterface $container)

if (!empty($config['person_fn']) && is_callable($config['person_fn'])) {
$config['person'] = null;
} else {

if (empty($config['person'])) {

$config['person_fn'] = function() use ($container) {

try {
$token = $container->get('security.token_storage')->getToken();

if ($token) {
$user = $token->getUser();
$serializer = $container->get('serializer');
$person = \json_decode($serializer->serialize($user, 'json'), true);
return $person;
}
} catch (\Exception $exception) {
// Ignore
} elseif (empty($config['person'])) {
$config['person_fn'] = function () use ($container) {

try {
$token = $container->get('security.token_storage')->getToken();

if ($token) {
$user = $token->getUser();
$serializer = $container->get('serializer');

return \json_decode($serializer->serialize($user, 'json'), true);
}
};

}

} catch (\Exception $exception) {
// Ignore
}
};
}

$this->minimumLevel = $config['minimum_level'] ?: LogLevel::ERROR;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, I recommend using monolog_minimum_level for the config option name as suggested in rollbar/rollbar-php#440 (review)

Also, I think isset($config['minimum_level']) is needed here as I get PHP notices if minimum_level is not set in rollbar.yaml:

$this->minimumLevel = isset($config['minimum_level']) ? $config['minimum_level'] : LogLevel::ERROR;

Copy link
Author

@Yozhef Yozhef Mar 18, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ArturMoczulski okay, i change it validation, but I do not like the name of this option. I answer rollbar/rollbar-php#440 (review)


Rollbar::init($config, false, false, false);
}

Expand All @@ -64,6 +65,6 @@ public function __construct(ContainerInterface $container)
*/
public function createRollbarHandler()
{
return new RollbarHandler(Rollbar::logger(), LogLevel::ERROR);
return new RollbarHandler(Rollbar::logger(), $this->minimumLevel);
}
}