mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-08 22:26:41 +02:00
Merge remote-tracking branch 'cbergau/master'
This commit is contained in:
@@ -126,6 +126,7 @@ Handlers
|
|||||||
- _DoctrineCouchDBHandler_: Logs records to a CouchDB server via the Doctrine CouchDB ODM.
|
- _DoctrineCouchDBHandler_: Logs records to a CouchDB server via the Doctrine CouchDB ODM.
|
||||||
- _RavenHandler_: Logs records to a [Sentry](http://getsentry.com/) server using
|
- _RavenHandler_: Logs records to a [Sentry](http://getsentry.com/) server using
|
||||||
[raven](https://packagist.org/packages/raven/raven).
|
[raven](https://packagist.org/packages/raven/raven).
|
||||||
|
- _ZendMonitorHandler_: Logs records to the ZendMonitor.
|
||||||
|
|
||||||
Wrappers / Special Handlers
|
Wrappers / Special Handlers
|
||||||
---------------------------
|
---------------------------
|
||||||
|
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
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
95
src/Monolog/Handler/ZendMonitorHandler.php
Normal file
95
src/Monolog/Handler/ZendMonitorHandler.php
Normal file
@@ -0,0 +1,95 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
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 = 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,
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct
|
||||||
|
*
|
||||||
|
* @param int $level
|
||||||
|
* @param bool $bubble
|
||||||
|
* @throws MissingExtensionException
|
||||||
|
*/
|
||||||
|
public function __construct($level = Logger::DEBUG, $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)
|
||||||
|
{
|
||||||
|
$this->writeZendMonitorCustomEvent(
|
||||||
|
$this->levelMap[$record['level']],
|
||||||
|
$record['message'],
|
||||||
|
$record['formatted']
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write a record to Zend Monitor
|
||||||
|
*
|
||||||
|
* @param int $level
|
||||||
|
* @param string $message
|
||||||
|
* @param array $formatted
|
||||||
|
*/
|
||||||
|
protected function writeZendMonitorCustomEvent($level, $message, $formatted)
|
||||||
|
{
|
||||||
|
zend_monitor_custom_event($level, $message, $formatted);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function getDefaultFormatter()
|
||||||
|
{
|
||||||
|
return new NormalizerFormatter();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the level map
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function getLevelMap()
|
||||||
|
{
|
||||||
|
return $this->levelMap;
|
||||||
|
}
|
||||||
|
}
|
70
tests/Monolog/Handler/ZendMonitorHandlerTest.php
Normal file
70
tests/Monolog/Handler/ZendMonitorHandlerTest.php
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
use Monolog\Logger;
|
||||||
|
use Monolog\TestCase;
|
||||||
|
|
||||||
|
class ZendMonitorHandlerTest extends TestCase
|
||||||
|
{
|
||||||
|
protected $zendMonitorHandler;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
if (!function_exists('zend_monitor_custom_event')) {
|
||||||
|
$this->markTestSkipped('ZendServer is not installed');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Monolog\Handler\ZendMonitorHandler::write
|
||||||
|
*/
|
||||||
|
public function testWrite()
|
||||||
|
{
|
||||||
|
$record = $this->getRecord();
|
||||||
|
$formatterResult = array(
|
||||||
|
'message' => $record['message']
|
||||||
|
);
|
||||||
|
|
||||||
|
$zendMonitor = $this->getMockBuilder('Monolog\Handler\ZendMonitorHandler')
|
||||||
|
->setMethods(array('writeZendMonitorCustomEvent', 'getDefaultFormatter'))
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$formatterMock = $this->getMockBuilder('Monolog\Formatter\NormalizerFormatter')
|
||||||
|
->disableOriginalConstructor()
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$formatterMock->expects($this->once())
|
||||||
|
->method('format')
|
||||||
|
->will($this->returnValue($formatterResult));
|
||||||
|
|
||||||
|
$zendMonitor->expects($this->once())
|
||||||
|
->method('getDefaultFormatter')
|
||||||
|
->will($this->returnValue($formatterMock));
|
||||||
|
|
||||||
|
$levelMap = $zendMonitor->getLevelMap();
|
||||||
|
|
||||||
|
$zendMonitor->expects($this->once())
|
||||||
|
->method('writeZendMonitorCustomEvent')
|
||||||
|
->with($levelMap[$record['level']], $record['message'], $formatterResult);
|
||||||
|
|
||||||
|
$zendMonitor->handle($record);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @covers Monolog\Handler\ZendMonitorHandler::getDefaultFormatter
|
||||||
|
*/
|
||||||
|
public function testGetDefaultFormatterReturnsNormalizerFormatter()
|
||||||
|
{
|
||||||
|
$zendMonitor = new ZendMonitorHandler();
|
||||||
|
$this->assertInstanceOf('Monolog\Formatter\NormalizerFormatter', $zendMonitor->getDefaultFormatter());
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user