Skip to content

Correctly set severity for Monolog messages #505

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

Merged
merged 2 commits into from
Jul 22, 2021
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## Unreleased

- Update phpdoc on facade for better IDE autocompletion (#504)
- Exceptions captured using log channels (Monolog) will now have the correct severity set (#505)

## 2.7.0

Expand Down
11 changes: 6 additions & 5 deletions src/Sentry/Laravel/SentryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public function getBatchFormatter(): FormatterInterface
*
* @return \Sentry\Severity
*/
protected function getLogLevel($logLevel)
protected function getLogLevel(int $logLevel): Severity
{
switch ($logLevel) {
case Logger::DEBUG:
Expand All @@ -154,12 +154,13 @@ protected function getLogLevel($logLevel)
return Severity::info();
case Logger::WARNING:
return Severity::warning();
case Logger::ERROR:
return Severity::error();
case Logger::ALERT:
case Logger::EMERGENCY:
case Logger::CRITICAL:
return Severity::fatal();
case Logger::ERROR:
default:
return Severity::error();
}
}

Expand Down Expand Up @@ -218,6 +219,7 @@ function (Scope $scope) use ($record, $isException, $exception) {

$scope->addEventProcessor(
function (Event $event) use ($record, $logger) {
$event->setLevel($this->getLogLevel($record['level']));
$event->setLogger($logger);

if (!empty($this->environment) && !$event->getEnvironment()) {
Expand All @@ -242,8 +244,7 @@ function (Event $event) use ($record, $logger) {
$this->hub->captureMessage(
$this->useFormattedMessage || empty($record['message'])
? $record['formatted']
: $record['message'],
$this->getLogLevel($record['level'])
: $record['message']
);
}
}
Expand Down