1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-07-31 18:30:15 +02:00

the appname can now be set from the handler's constructor

This commit is contained in:
odino
2013-08-26 13:20:13 +04:00
parent db3df1a1fa
commit 165778963e
2 changed files with 75 additions and 6 deletions

View File

@@ -13,9 +13,17 @@ namespace Monolog\Handler;
use Monolog\TestCase;
use Monolog\Logger;
use Psr\Log\LogLevel;
class NewRelicHandlerTest extends TestCase
{
public static $appname;
public function setUp()
{
$this::$appname = null;
}
/**
* @expectedException Monolog\Handler\MissingExtensionException
*/
@@ -42,6 +50,30 @@ class NewRelicHandlerTest extends TestCase
$handler = new StubNewRelicHandler();
$handler->handle($this->getRecord(Logger::ERROR, 'log message', array('appname' => 'myApp')));
}
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);
}
}
class StubNewRelicHandlerWithoutExtension extends NewRelicHandler
@@ -65,9 +97,9 @@ function newrelic_notice_error()
return true;
}
function newrelic_set_appname()
function newrelic_set_appname($appname)
{
return true;
return NewRelicHandlerTest::$appname = $appname;
}
function newrelic_add_custom_parameter()