PluginProbe
WCPOS – Point of Sale (POS) plugin for WooCommerce / 1.10.23
WCPOS – Point of Sale (POS) plugin for WooCommerce v1.10.23
1.10.24 1.10.23 1.10.22 1.10.21 1.10.20 1.10.19 1.10.18 1.10.17 1.10.16 1.10.15 1.10.13 1.10.14 1.10.12 1.10.11 1.10.10 1.10.9 1.10.8 untagged-3d9b7ccddc54df87c672 1.10.7 1.10.6 1.10.5 1.10.3 1.10.4 1.10.2 1.10.1 All 168 releases
woocommerce-pos / vendor_prefixed / sentry / sentry / src / Monolog / Handler.php

Handler.php in WCPOS – Point of Sale (POS) plugin for WooCommerce 1.10.23, at vendor_prefixed/sentry/sentry/src/Monolog/Handler.php

111 lines 3.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare (strict_types=1);
4 namespace WCPOS\Vendor\Sentry\Monolog;
5
6 use WCPOS\Vendor\Monolog\Handler\AbstractProcessingHandler;
7 use WCPOS\Vendor\Monolog\Logger;
8 use WCPOS\Vendor\Monolog\LogRecord;
9 use WCPOS\Vendor\Sentry\Event;
10 use WCPOS\Vendor\Sentry\EventHint;
11 use WCPOS\Vendor\Sentry\State\HubInterface;
12 use WCPOS\Vendor\Sentry\State\Scope;
13 /**
14 * This Monolog handler logs every message to a Sentry's server using the given
15 * hub instance.
16 *
17 * @deprecated since version 4.24. To be removed in version 5.0. Use {@see LogsHandler}
18 * for Sentry logs, {@see ExceptionToSentryIssueHandler} to send Monolog exceptions
19 * to Sentry issues, and {@see LogToSentryIssueHandler}
20 * to send Monolog log messages to Sentry issues.
21 *
22 * @author Stefano Arlandini <[email protected]>
23 */
24 final class Handler extends AbstractProcessingHandler
25 {
26 use CompatibilityProcessingHandlerTrait;
27 private const CONTEXT_EXCEPTION_KEY = 'exception';
28 /**
29 * @var HubInterface
30 */
31 private $hub;
32 /**
33 * @var bool
34 */
35 private $fillExtraContext;
36 /**
37 * {@inheritdoc}
38 *
39 * @param HubInterface $hub The hub to which errors are reported
40 */
41 public function __construct(HubInterface $hub, $level = Logger::DEBUG, bool $bubble = \true, bool $fillExtraContext = \false)
42 {
43 parent::__construct($level, $bubble);
44 $this->hub = $hub;
45 $this->fillExtraContext = $fillExtraContext;
46 }
47 /**
48 * @param array<string, mixed>|LogRecord $record
49 */
50 protected function doWrite($record) : void
51 {
52 $event = Event::createEvent();
53 $event->setLevel(self::getSeverityFromLevel($record['level']));
54 $event->setMessage($record['message']);
55 $event->setLogger(\sprintf('monolog.%s', $record['channel']));
56 $hint = new EventHint();
57 if (isset($record['context']['exception']) && $record['context']['exception'] instanceof \Throwable) {
58 $hint->exception = $record['context']['exception'];
59 }
60 $this->hub->withScope(function (Scope $scope) use($record, $event, $hint) : void {
61 $scope->setExtra('monolog.channel', $record['channel']);
62 $scope->setExtra('monolog.level', $record['level_name']);
63 $monologContextData = $this->getMonologContextData($record['context']);
64 if ($monologContextData !== []) {
65 $scope->setExtra('monolog.context', $monologContextData);
66 }
67 $monologExtraData = $this->getMonologExtraData($record['extra']);
68 if ($monologExtraData !== []) {
69 $scope->setExtra('monolog.extra', $monologExtraData);
70 }
71 $this->hub->captureEvent($event, $hint);
72 });
73 }
74 /**
75 * @param mixed[] $context
76 *
77 * @return mixed[]
78 */
79 private function getMonologContextData(array $context) : array
80 {
81 if (!$this->fillExtraContext) {
82 return [];
83 }
84 $contextData = [];
85 foreach ($context as $key => $value) {
86 // We skip the `exception` field because it goes in its own context
87 if ($key === self::CONTEXT_EXCEPTION_KEY) {
88 continue;
89 }
90 $contextData[$key] = $value;
91 }
92 return $contextData;
93 }
94 /**
95 * @param mixed[] $context
96 *
97 * @return mixed[]
98 */
99 private function getMonologExtraData(array $context) : array
100 {
101 if (!$this->fillExtraContext) {
102 return [];
103 }
104 $extraData = [];
105 foreach ($context as $key => $value) {
106 $extraData[$key] = $value;
107 }
108 return $extraData;
109 }
110 }
111