PluginProbe
Media Cloud Sync / 1.4.2
Media Cloud Sync v1.4.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / google / monolog / monolog / src / Monolog / Handler / ZendMonitorHandler.php

ZendMonitorHandler.php in Media Cloud Sync 1.4.2, at includes/sdk/google/monolog/monolog/src/Monolog/Handler/ZendMonitorHandler.php

78 lines 3.0 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 /*
5 * This file is part of the Monolog package.
6 *
7 * (c) Jordi Boggiano <[email protected]>
8 *
9 * For the full copyright and license information, please view the LICENSE
10 * file that was distributed with this source code.
11 */
12 namespace Dudlewebs\WPMCS\GCP\Monolog\Handler;
13
14 use Dudlewebs\WPMCS\GCP\Monolog\Formatter\FormatterInterface;
15 use Dudlewebs\WPMCS\GCP\Monolog\Formatter\NormalizerFormatter;
16 use Dudlewebs\WPMCS\GCP\Monolog\Level;
17 use Dudlewebs\WPMCS\GCP\Monolog\LogRecord;
18 /**
19 * Handler sending logs to Zend Monitor
20 *
21 * @author Christian Bergau <[email protected]>
22 * @author Jason Davis <[email protected]>
23 */
24 class ZendMonitorHandler extends AbstractProcessingHandler
25 {
26 /**
27 * @throws MissingExtensionException
28 */
29 public function __construct(int|string|Level $level = Level::Debug, bool $bubble = \true)
30 {
31 if (!\function_exists('Dudlewebs\\WPMCS\\GCP\\zend_monitor_custom_event')) {
32 throw new MissingExtensionException('You must have Zend Server installed with Zend Monitor enabled in order to use this handler');
33 }
34 parent::__construct($level, $bubble);
35 }
36 /**
37 * Translates Monolog log levels to ZendMonitor levels.
38 */
39 protected function toZendMonitorLevel(Level $level) : int
40 {
41 return match ($level) {
42 Level::Debug => \Dudlewebs\WPMCS\GCP\ZEND_MONITOR_EVENT_SEVERITY_INFO,
43 Level::Info => \Dudlewebs\WPMCS\GCP\ZEND_MONITOR_EVENT_SEVERITY_INFO,
44 Level::Notice => \Dudlewebs\WPMCS\GCP\ZEND_MONITOR_EVENT_SEVERITY_INFO,
45 Level::Warning => \Dudlewebs\WPMCS\GCP\ZEND_MONITOR_EVENT_SEVERITY_WARNING,
46 Level::Error => \Dudlewebs\WPMCS\GCP\ZEND_MONITOR_EVENT_SEVERITY_ERROR,
47 Level::Critical => \Dudlewebs\WPMCS\GCP\ZEND_MONITOR_EVENT_SEVERITY_ERROR,
48 Level::Alert => \Dudlewebs\WPMCS\GCP\ZEND_MONITOR_EVENT_SEVERITY_ERROR,
49 Level::Emergency => \Dudlewebs\WPMCS\GCP\ZEND_MONITOR_EVENT_SEVERITY_ERROR,
50 };
51 }
52 /**
53 * @inheritDoc
54 */
55 protected function write(LogRecord $record) : void
56 {
57 $this->writeZendMonitorCustomEvent($record->level->getName(), $record->message, $record->formatted, $this->toZendMonitorLevel($record->level));
58 }
59 /**
60 * Write to Zend Monitor Events
61 * @param string $type Text displayed in "Class Name (custom)" field
62 * @param string $message Text displayed in "Error String"
63 * @param array<mixed> $formatted Displayed in Custom Variables tab
64 * @param int $severity Set the event severity level (-1,0,1)
65 */
66 protected function writeZendMonitorCustomEvent(string $type, string $message, array $formatted, int $severity) : void
67 {
68 zend_monitor_custom_event($type, $message, $formatted, $severity);
69 }
70 /**
71 * @inheritDoc
72 */
73 public function getDefaultFormatter() : FormatterInterface
74 {
75 return new NormalizerFormatter();
76 }
77 }
78