mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-04 20:27:31 +02:00
Exception will be thrown if ZendMonitorHandler is instantiated without having Zend Server installed.
This commit is contained in:
22
src/Monolog/Handler/MissingExtensionException.php
Normal file
22
src/Monolog/Handler/MissingExtensionException.php
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exception can be thrown if an extension for an handler is missing
|
||||||
|
*
|
||||||
|
* @author Christian Bergau <cbergau86@gmail.com>
|
||||||
|
*/
|
||||||
|
class MissingExtensionException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
@@ -36,22 +36,18 @@ class ZendMonitorHandler extends AbstractProcessingHandler
|
|||||||
Logger::EMERGENCY => 0,
|
Logger::EMERGENCY => 0,
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Is application running on a zend server?
|
|
||||||
*
|
|
||||||
* @var bool
|
|
||||||
*/
|
|
||||||
protected $isZendServer = false;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct
|
* Construct
|
||||||
*
|
*
|
||||||
* @param int $level
|
* @param int $level
|
||||||
* @param bool $bubble
|
* @param bool $bubble
|
||||||
|
* @throws MissingExtensionException
|
||||||
*/
|
*/
|
||||||
public function __construct($level = Logger::DEBUG, $bubble = true)
|
public function __construct($level = Logger::DEBUG, $bubble = true)
|
||||||
{
|
{
|
||||||
$this->isZendServer = function_exists('zend_monitor_custom_event');
|
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);
|
parent::__construct($level, $bubble);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,13 +56,11 @@ class ZendMonitorHandler extends AbstractProcessingHandler
|
|||||||
*/
|
*/
|
||||||
protected function write(array $record)
|
protected function write(array $record)
|
||||||
{
|
{
|
||||||
if ($this->isZendServer()) {
|
$this->writeZendMonitorCustomEvent(
|
||||||
$this->writeZendMonitorCustomEvent(
|
$this->levelMap[$record['level']],
|
||||||
$this->levelMap[$record['level']],
|
$record['message'],
|
||||||
$record['message'],
|
$record['formatted']
|
||||||
$record['formatted']
|
);
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -98,14 +92,4 @@ class ZendMonitorHandler extends AbstractProcessingHandler
|
|||||||
{
|
{
|
||||||
return $this->levelMap;
|
return $this->levelMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Is Zend Server?
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function isZendServer()
|
|
||||||
{
|
|
||||||
return $this->isZendServer;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -25,17 +25,7 @@ class ZendMonitorHandlerTest extends TestCase
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @covers \Monolog\Handler\ZendMonitor::__construct
|
* @covers Monolog\Handler\ZendMonitorHandler::write
|
||||||
* @covers \Monolog\Handler\ZendMonitor::isZendServer
|
|
||||||
*/
|
|
||||||
public function testIsZendServerReturnsTrue()
|
|
||||||
{
|
|
||||||
$zendMonitor = new ZendMonitorHandler();
|
|
||||||
$this->assertTrue($zendMonitor->isZendServer());
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @covers \Monolog\Handler\ZendMonitor::write
|
|
||||||
*/
|
*/
|
||||||
public function testWrite()
|
public function testWrite()
|
||||||
{
|
{
|
||||||
@@ -69,6 +59,9 @@ class ZendMonitorHandlerTest extends TestCase
|
|||||||
$zendMonitor->handle($record);
|
$zendMonitor->handle($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Monolog\Handler\ZendMonitorHandler::getDefaultFormatter
|
||||||
|
*/
|
||||||
public function testGetDefaultFormatterReturnsNormalizerFormatter()
|
public function testGetDefaultFormatterReturnsNormalizerFormatter()
|
||||||
{
|
{
|
||||||
$zendMonitor = new ZendMonitorHandler();
|
$zendMonitor = new ZendMonitorHandler();
|
||||||
|
Reference in New Issue
Block a user