* * 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 */ 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; } }