File tree Expand file tree Collapse file tree 3 files changed +62
-1
lines changed Expand file tree Collapse file tree 3 files changed +62
-1
lines changed Original file line number Diff line number Diff line change 1818 <code ><![CDATA[ isMasterRequest]]> </code >
1919 </UndefinedMethod >
2020 </file >
21+ <file src =" src/Monolog/LogsHandler.php" >
22+ <InvalidParamDefault >
23+ <code ><![CDATA[ value-of<MonologLevel::VALUES>|value-of<MonologLevel::NAMES>|MonologLevel|PsrLogLevel::*]]> </code >
24+ </InvalidParamDefault >
25+ <UndefinedClass >
26+ <code ><![CDATA[ value-of<MonologLevel::VALUES>|value-of<MonologLevel::NAMES>|MonologLevel|PsrLogLevel::*]]> </code >
27+ </UndefinedClass >
28+ <UndefinedDocblockClass >
29+ <code ><![CDATA[ value-of<MonologLevel::VALUES>|value-of<MonologLevel::NAMES>|MonologLevel|PsrLogLevel::*]]> </code >
30+ </UndefinedDocblockClass >
31+ <UnresolvableConstant >
32+ <code ><![CDATA[ value-of<MonologLevel::VALUES>|value-of<MonologLevel::NAMES>|MonologLevel|PsrLogLevel::*]]> </code >
33+ </UnresolvableConstant >
34+ </file >
2135 <file src =" src/Tracing/Cache/TraceableCacheAdapterTrait.php" >
2236 <LessSpecificImplementedReturnType >
2337 <code ><![CDATA[ iterable]]> </code >
Original file line number Diff line number Diff line change 44
55namespace Sentry \SentryBundle \Monolog ;
66
7+ use Monolog \Level as MonologLevel ;
78use Monolog \Logger as MonologLogger ;
89use Monolog \LogRecord ;
10+ use Psr \Log \LogLevel as PsrLogLevel ;
911use Sentry \Monolog \CompatibilityLogLevelTrait ;
1012use Sentry \Monolog \LogsHandler as BaseLogsHandler ;
1113
@@ -18,8 +20,17 @@ class LogsHandler extends BaseLogsHandler
1820{
1921 use CompatibilityLogLevelTrait;
2022
21- public function __construct (int $ level = MonologLogger::DEBUG , bool $ bubble = true )
23+ /**
24+ * @param int|string|MonologLevel|PsrLogLevel::* $level
25+ *
26+ * @phpstan-param value-of<MonologLevel::VALUES>|value-of<MonologLevel::NAMES>|MonologLevel|PsrLogLevel::* $level
27+ */
28+ public function __construct ($ level = MonologLogger::DEBUG , bool $ bubble = true )
2229 {
30+ $ level = MonologLogger::toMonologLevel ($ level );
31+ if ($ level instanceof MonologLevel) { // Monolog >= 3
32+ $ level = $ level ->value ;
33+ }
2334 $ logLevel = self ::getSentryLogLevelFromMonologLevel ($ level );
2435 parent ::__construct ($ logLevel , $ bubble );
2536 }
Original file line number Diff line number Diff line change 44
55namespace Sentry \SentryBundle \Tests \Monolog ;
66
7+ use Monolog \Level as MonologLevel ;
78use Monolog \Logger as MonologLogger ;
89use PHPUnit \Framework \TestCase ;
10+ use Psr \Log \LogLevel as PsrLogLevel ;
911use Sentry \SentryBundle \Monolog \LogsHandler ;
1012
1113final class LogsHandlerTest extends TestCase
@@ -48,4 +50,38 @@ public function testHandleReturnsTrueAboveThresholdWhenBubbleFalse(): void
4850
4951 $ this ->assertTrue ($ handler ->handle ($ record ));
5052 }
53+
54+ /**
55+ * @dataProvider levelProvider
56+ *
57+ * @param int|string|MonologLevel $level
58+ *
59+ * @phpstan-param value-of<MonologLevel::VALUES>|value-of<MonologLevel::NAMES>|MonologLevel|PsrLogLevel::* $level
60+ */
61+ public function testHandlerAcceptsVariousTypesAsLevel ($ level ): void
62+ {
63+ $ handler = new LogsHandler ($ level , false );
64+ $ record = [
65+ 'level ' => MonologLogger::WARNING ,
66+ 'message ' => 'msg ' ,
67+ 'context ' => [],
68+ 'extra ' => [],
69+ ];
70+
71+ $ this ->assertTrue ($ handler ->handle ($ record ));
72+ }
73+
74+ /**
75+ * @return iterable<array{0: int|string|MonologLevel}>
76+ */
77+ public static function levelProvider (): iterable
78+ {
79+ yield [MonologLogger::DEBUG ];
80+ yield ['DEBUG ' ];
81+ yield [PsrLogLevel::DEBUG ];
82+
83+ if (class_exists (MonologLevel::class)) {
84+ yield [MonologLevel::Debug];
85+ }
86+ }
5187}
You can’t perform that action at this time.
0 commit comments