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

Adds log-level configuration to PSR logger #23

Merged
merged 16 commits into from
Dec 13, 2017
Merged

Adds log-level configuration to PSR logger #23

merged 16 commits into from
Dec 13, 2017

Conversation

Cawllec
Copy link
Contributor

@Cawllec Cawllec commented Nov 1, 2017

This adds 3 new configuration options obtained through the Bugsnag-php config object for:

  • NotifyLevel: The LogLevel at which notifications will be sent to bugsnag
  • WarningLevel: The LogLevel at which notifications will be given a severity "warning"
  • ErrorLevel: The LogLevel at which notifications will be given a severity "error"

This requires an update of the PHP notifier and a dependency update before it can be merged.

@Cawllec Cawllec added the feature request Request for a new feature label Nov 1, 2017
@GrahamCampbell
Copy link
Contributor

StyleCI don't seem to be running on this repo?

@@ -17,6 +18,13 @@ class BugsnagLogger extends AbstractLogger
protected $client;

/**
* The minimum level required to notify bugsnag.
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be a note here to indicate that under the threshold, log messages are converted to breadcrumbs.

@@ -26,6 +34,8 @@ class BugsnagLogger extends AbstractLogger
public function __construct(Client $client)
{
$this->client = $client;
$logNotifyLevel = $this->client->getConfig()->getLogLevel();
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a roundabout way to set the log level by default. Loading it from the config prevents users from configuring the logger directly or separately from their initial Bugsnag configuration. In addition, it is potentially confusing for users who are using bugsnag-php without the logger, and may be conflated with setErrorReportingLevel for example. A setter would be preferable, with usage like:

$bugsnag = Bugsnag\Client::make('API KEY');
$logger = new Bugsnag\PsrLogger\BugsnagLogger($bugsnag);

// Set minimum log-level for sending a report to Bugsnag
$logger->setLogReportingLevel(\Psr\Log\LogLevel::ERROR);

// Add breadcrumbs for low-severity log messages
$logger->notice("Reticulating splines");

// Log an exception to Bugsnag
$logger->error(new Exception("Invalid configuration at runtime"));

The existing constructor could be preserved and we can have new option for log level solely where needed, such as in config/bugsnag.php and an env variable for Laravel. The documentation would be something like:

Log reporting level

The log reporting level is the minimum log level (as specified by \Psr\Log\LogLevel) required to generate an error report to send to Bugsnag. All log messages below the selected level are recorded as breadcrumbs on subsequent reports.

You can set the Log reporting level by setting the BUGSNAG_LOG_REPORTING_LEVEL environment variable or by setting log_reporting_level within config/bugsnag.php:

"log_reporting_level" => "error"

By default, this is set to notice

@Cawllec
Copy link
Contributor Author

Cawllec commented Nov 15, 2017

Closing in favour of #27

@Cawllec Cawllec closed this Nov 15, 2017
@Cawllec
Copy link
Contributor Author

Cawllec commented Nov 15, 2017

Re-opening as primary logLevel PR

@Cawllec Cawllec reopened this Nov 15, 2017
* Add example of simpler usage, update test

* chore: Run the linter

* Added notifyLevel info to readme
public function setNotifyLevel($notifyLevel)
{
if (!in_array($notifyLevel, $this->getLogLevelOrder())) {
throw new TypeError("notifyLevel must be a valid Psr\Log\LogLevel value");
Copy link
Contributor

Choose a reason for hiding this comment

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

We should be careful with hard failures, crashing the whole library. I think in some other places, we raise warnings, such as if the http layer fails.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, TypeError doesn't exist in PHP 5, so can't be used here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was going to say we should log the error and ignore the invalid input, but then we are within the logger 🤔 😄

@kattrali kattrali merged commit ec0320f into master Dec 13, 2017
@kattrali kattrali deleted the logLevel branch December 13, 2017 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request Request for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants