| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- <?php declare(strict_types=1);
- /*
- * This file is part of the Monolog package.
- *
- * (c) Jordi Boggiano <j.boggiano@seld.be>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Monolog\Handler;
- use Monolog\Formatter\FormatterInterface;
- use Monolog\Formatter\NormalizerFormatter;
- use Monolog\Logger;
- /**
- * Handler sending logs to Zend Monitor
- *
- * @author Christian Bergau <cbergau86@gmail.com>
- */
- class ZendMonitorHandler extends AbstractProcessingHandler
- {
- /**
- * Monolog level / ZendMonitor Custom Event priority map
- *
- * @var array
- */
- protected $levelMap = [
- Logger::DEBUG => 1,
- Logger::INFO => 2,
- Logger::NOTICE => 3,
- Logger::WARNING => 4,
- Logger::ERROR => 5,
- Logger::CRITICAL => 6,
- Logger::ALERT => 7,
- Logger::EMERGENCY => 0,
- ];
- /**
- * @param string|int $level The minimum logging level at which this handler will be triggered.
- * @param bool $bubble Whether the messages that are handled can bubble up the stack or not.
- * @throws MissingExtensionException
- */
- public function __construct($level = Logger::DEBUG, bool $bubble = true)
- {
- if (!function_exists('zend_monitor_custom_event')) {
- throw new MissingExtensionException('You must have Zend Server installed in order to use this handler');
- }
- parent::__construct($level, $bubble);
- }
- /**
- * {@inheritdoc}
- */
- protected function write(array $record): void
- {
- $this->writeZendMonitorCustomEvent(
- $this->levelMap[$record['level']],
- $record['message'],
- $record['formatted']
- );
- }
- protected function writeZendMonitorCustomEvent(int $level, string $message, array $formatted): void
- {
- zend_monitor_custom_event($level, $message, $formatted);
- }
- /**
- * {@inheritdoc}
- */
- public function getDefaultFormatter(): FormatterInterface
- {
- return new NormalizerFormatter();
- }
- public function getLevelMap(): array
- {
- return $this->levelMap;
- }
- }
|