* * 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\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 = array( Logger::DEBUG => 1, Logger::INFO => 2, Logger::NOTICE => 3, Logger::WARNING => 4, Logger::ERROR => 5, Logger::CRITICAL => 6, Logger::ALERT => 7, Logger::EMERGENCY => 0, ); /** * Is application running on a zend server? * * @var bool */ protected $isZendServer = false; /** * Construct * * @param int $level * @param bool $bubble */ public function __construct($level = Logger::DEBUG, $bubble = true) { $this->isZendServer = function_exists('zend_monitor_custom_event'); parent::__construct($level, $bubble); } /** * {@inheritdoc} */ protected function write(array $record) { if ($this->isZendServer()) { $formatter = new NormalizerFormatter(); $record = $formatter->format($record); $this->writeZendMonitorCustomEvent($record['level'], $record['message']); } } /** * Write a record to Zend Monitor * * @param int $level * @param string $message */ protected function writeZendMonitorCustomEvent($level, $message) { zend_monitor_custom_event($level, $message); } /** * Is Zend Server? * * @return bool */ public function isZendServer() { return $this->isZendServer; } }