mirror of
https://github.com/Seldaek/monolog.git
synced 2025-02-24 15:02:28 +01:00
Added an handler for NewRelic:
* implemented a test which verifies that the fallback handler handles records when the NewRelic PHP extension is not installes * implemented the actual handler
This commit is contained in:
parent
050bb52fd8
commit
b439707cbb
49
src/Monolog/Handler/NewRelicHandler.php
Normal file
49
src/Monolog/Handler/NewRelicHandler.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Base class for all mail handlers
|
||||||
|
*
|
||||||
|
* @author Gyula Sallai
|
||||||
|
*/
|
||||||
|
class NewRelicHandler extends AbstractProcessingHandler
|
||||||
|
{
|
||||||
|
protected $fallbackHandler;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
protected function write(array $record)
|
||||||
|
{
|
||||||
|
if (extension_loaded('newrelic')) {
|
||||||
|
newrelic_notice_error($record['message']);
|
||||||
|
|
||||||
|
foreach ($record['context'] as $key => $parameter) {
|
||||||
|
newrelic_add_custom_parameter($key, $parameter);
|
||||||
|
}
|
||||||
|
} elseif ($this->fallbackHandler instanceOf AbstractProcessingHandler) {
|
||||||
|
$this->fallbackHandler->write($record);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the fallback handler to be used to log informations if the New Relic
|
||||||
|
* extension is not available.
|
||||||
|
*
|
||||||
|
* @param Monolog\Handler\AbstractProcessingHandler $handler
|
||||||
|
*/
|
||||||
|
public function setFallbackHandler(AbstractProcessingHandler $handler)
|
||||||
|
{
|
||||||
|
$this->fallbackHandler = $handler;
|
||||||
|
}
|
||||||
|
}
|
33
tests/Monolog/Handler/NewRelicHandlerTest.php
Normal file
33
tests/Monolog/Handler/NewRelicHandlerTest.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?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\TestCase;
|
||||||
|
use Monolog\Logger;
|
||||||
|
|
||||||
|
class NewRelicHandlerTest extends TestCase
|
||||||
|
{
|
||||||
|
public function testFallbackHandler()
|
||||||
|
{
|
||||||
|
$handler = new NewRelicHandler();
|
||||||
|
$fallbackHandler = new TestHandler();
|
||||||
|
$handler->setFallbackHandler($fallbackHandler);
|
||||||
|
$record = array(
|
||||||
|
'level' => Logger::DEBUG,
|
||||||
|
'extra' => array(),
|
||||||
|
);
|
||||||
|
|
||||||
|
$handler->handle($record);
|
||||||
|
|
||||||
|
$this->assertCount(1, $fallbackHandler->getRecords());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user