-
Notifications
You must be signed in to change notification settings - Fork 185
fix(logs): Allow passing string and enum Monolog level #959
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,10 @@ | |
|
||
namespace Sentry\SentryBundle\Monolog; | ||
|
||
use Monolog\Level as MonologLevel; | ||
use Monolog\Logger as MonologLogger; | ||
use Monolog\LogRecord; | ||
use Psr\Log\LogLevel as PsrLogLevel; | ||
use Sentry\Monolog\CompatibilityLogLevelTrait; | ||
use Sentry\Monolog\LogsHandler as BaseLogsHandler; | ||
|
||
|
@@ -18,8 +20,17 @@ class LogsHandler extends BaseLogsHandler | |
{ | ||
use CompatibilityLogLevelTrait; | ||
|
||
public function __construct(int $level = MonologLogger::DEBUG, bool $bubble = true) | ||
/** | ||
* @param int|string|MonologLevel|PsrLogLevel::* $level | ||
* | ||
* @phpstan-param value-of<MonologLevel::VALUES>|value-of<MonologLevel::NAMES>|MonologLevel|PsrLogLevel::* $level | ||
*/ | ||
public function __construct($level = MonologLogger::DEBUG, bool $bubble = true) | ||
{ | ||
$level = MonologLogger::toMonologLevel($level); | ||
|
||
if ($level instanceof MonologLevel) { // Monolog >= 3 | ||
$level = $level->value; | ||
} | ||
$logLevel = self::getSentryLogLevelFromMonologLevel($level); | ||
parent::__construct($logLevel, $bubble); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to be a bug in Psalm when using const on enums: https://psalm.dev/r/a6f9298b82