44
55namespace Sentry \SentryBundle \Monolog ;
66
7- use Monolog \Formatter \FormatterInterface ;
8- use Monolog \Handler \HandlerInterface ;
97use Monolog \Logger as MonologLogger ;
108use Monolog \LogRecord ;
119use Sentry \Monolog \CompatibilityLogLevelTrait ;
1210use Sentry \Monolog \LogsHandler as BaseLogsHandler ;
1311
1412/**
15- * Wrapper for the Sentry LogsHandler that uses Monolog constants for initialization .
16- * Sentry's LogLevel classes cannot be properly used in Symfony configuration so this acts as
17- * a service facade that can be instantiated using yml /xml config files .
13+ * Extends the base LogsHandler so that it can be used with Monolog constants .
14+ * Sentry LogLevel objects are not easily usable with symfony config files, so this provides
15+ * a convenient way to instantiate the service in yaml /xml.
1816 */
19- class LogsHandler implements HandlerInterface
17+ class LogsHandler extends BaseLogsHandler
2018{
2119 use CompatibilityLogLevelTrait;
2220
23- /**
24- * @var BaseLogsHandler
25- */
26- private $ logsHandler ;
27-
2821 public function __construct (int $ level = MonologLogger::DEBUG , bool $ bubble = true )
2922 {
3023 $ logLevel = self ::getSentryLogLevelFromMonologLevel ($ level );
31- $ this ->logsHandler = new BaseLogsHandler ($ logLevel , $ bubble );
32- }
33-
34- /**
35- * @param array<string, mixed>|LogRecord $record
36- */
37- public function isHandling ($ record ): bool
38- {
39- return $ this ->logsHandler ->isHandling ($ record );
24+ parent ::__construct ($ logLevel , $ bubble );
4025 }
4126
4227 /**
@@ -46,49 +31,10 @@ public function handle($record): bool
4631 {
4732 // Extra check required here because `isHandling` is not guaranteed to
4833 // be called, and we might accidentally capture log messages that should be filtered.
49- if ($ this ->logsHandler -> isHandling ($ record )) {
50- return $ this -> logsHandler -> handle ($ record );
34+ if ($ this ->isHandling ($ record )) {
35+ return parent :: handle ($ record );
5136 }
5237
5338 return false ;
5439 }
55-
56- /**
57- * @param array<array<string, mixed>|LogRecord> $records
58- */
59- public function handleBatch (array $ records ): void
60- {
61- $ this ->logsHandler ->handleBatch ($ records );
62- }
63-
64- public function close (): void
65- {
66- $ this ->logsHandler ->close ();
67- }
68-
69- /**
70- * @param callable $callback
71- */
72- public function pushProcessor ($ callback ): void
73- {
74- $ this ->logsHandler ->pushProcessor ($ callback );
75- }
76-
77- /**
78- * @return callable
79- */
80- public function popProcessor ()
81- {
82- return $ this ->logsHandler ->popProcessor ();
83- }
84-
85- public function setFormatter (FormatterInterface $ formatter ): void
86- {
87- $ this ->logsHandler ->setFormatter ($ formatter );
88- }
89-
90- public function getFormatter (): FormatterInterface
91- {
92- return $ this ->logsHandler ->getFormatter ();
93- }
9440}
0 commit comments