2012-08-23 00:43:49 +04:00
|
|
|
<?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;
|
2013-08-26 13:20:13 +04:00
|
|
|
use Psr\Log\LogLevel;
|
2012-08-23 00:43:49 +04:00
|
|
|
|
|
|
|
class NewRelicHandlerTest extends TestCase
|
2013-07-28 23:19:20 +02:00
|
|
|
{
|
2013-08-26 13:20:13 +04:00
|
|
|
public static $appname;
|
|
|
|
|
|
|
|
public function setUp()
|
|
|
|
{
|
|
|
|
$this::$appname = null;
|
|
|
|
}
|
|
|
|
|
2013-07-24 10:14:35 +04:00
|
|
|
/**
|
|
|
|
* @expectedException Monolog\Handler\MissingExtensionException
|
|
|
|
*/
|
|
|
|
public function testThehandlerThrowsAnExceptionIfTheNRExtensionIsNotLoaded()
|
|
|
|
{
|
|
|
|
$handler = new StubNewRelicHandlerWithoutExtension();
|
2013-07-28 23:19:20 +02:00
|
|
|
$handler->handle($this->getRecord(Logger::ERROR));
|
2013-07-24 10:14:35 +04:00
|
|
|
}
|
2013-07-28 23:19:20 +02:00
|
|
|
|
2013-07-24 10:14:35 +04:00
|
|
|
public function testThehandlerCanHandleTheRecord()
|
|
|
|
{
|
|
|
|
$handler = new StubNewRelicHandler();
|
2013-07-28 23:19:20 +02:00
|
|
|
$handler->handle($this->getRecord(Logger::ERROR));
|
2013-07-24 10:14:35 +04:00
|
|
|
}
|
2013-07-28 23:19:20 +02:00
|
|
|
|
2013-07-24 10:14:35 +04:00
|
|
|
public function testThehandlerCanAddParamsToTheNewRelicTrace()
|
|
|
|
{
|
|
|
|
$handler = new StubNewRelicHandler();
|
2013-07-28 23:19:20 +02:00
|
|
|
$handler->handle($this->getRecord(Logger::ERROR, 'log message', array('a' => 'b')));
|
2013-07-24 10:14:35 +04:00
|
|
|
}
|
2013-08-26 12:04:22 +04:00
|
|
|
|
2013-08-26 13:20:13 +04:00
|
|
|
public function testTheAppNameIsNullByDefault()
|
|
|
|
{
|
|
|
|
$handler = new StubNewRelicHandler();
|
|
|
|
$handler->handle($this->getRecord(Logger::ERROR, 'log message'));
|
|
|
|
|
|
|
|
$this->assertEquals(null, $this::$appname);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTheAppNameCanBeInjectedFromtheConstructor()
|
|
|
|
{
|
|
|
|
$handler = new StubNewRelicHandler(LogLevel::ALERT, false, 'myAppName');
|
|
|
|
$handler->handle($this->getRecord(Logger::ERROR, 'log message'));
|
|
|
|
|
|
|
|
$this->assertEquals('myAppName', $this::$appname);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testTheAppNameCanBeOverriddenFromEachLog()
|
|
|
|
{
|
|
|
|
$handler = new StubNewRelicHandler(LogLevel::ALERT, false, 'myAppName');
|
|
|
|
$handler->handle($this->getRecord(Logger::ERROR, 'log message', array('appname' => 'logAppName')));
|
|
|
|
|
|
|
|
$this->assertEquals('logAppName', $this::$appname);
|
|
|
|
}
|
2013-07-24 10:14:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
class StubNewRelicHandlerWithoutExtension extends NewRelicHandler
|
2012-08-23 00:43:49 +04:00
|
|
|
{
|
2013-07-24 10:14:35 +04:00
|
|
|
protected function isNewRelicEnabled()
|
2012-08-23 00:43:49 +04:00
|
|
|
{
|
2013-07-24 10:14:35 +04:00
|
|
|
return false;
|
2012-08-23 00:43:49 +04:00
|
|
|
}
|
|
|
|
}
|
2013-07-24 10:14:35 +04:00
|
|
|
|
|
|
|
class StubNewRelicHandler extends NewRelicHandler
|
|
|
|
{
|
|
|
|
protected function isNewRelicEnabled()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-29 00:08:51 +02:00
|
|
|
function newrelic_notice_error()
|
|
|
|
{
|
2013-07-24 10:14:35 +04:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-26 13:20:13 +04:00
|
|
|
function newrelic_set_appname($appname)
|
2013-08-26 12:04:22 +04:00
|
|
|
{
|
2013-08-26 13:20:13 +04:00
|
|
|
return NewRelicHandlerTest::$appname = $appname;
|
2013-08-26 12:04:22 +04:00
|
|
|
}
|
|
|
|
|
2013-07-29 00:08:51 +02:00
|
|
|
function newrelic_add_custom_parameter()
|
|
|
|
{
|
2013-07-24 10:14:35 +04:00
|
|
|
return true;
|
|
|
|
}
|