1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-05 20:57:36 +02:00

Add possibility to pass handlers/processors to Logger::__construct, fixes #157

This commit is contained in:
Jordi Boggiano
2013-02-13 19:06:07 +01:00
parent 237a147b9c
commit 9f515d47ce
2 changed files with 36 additions and 5 deletions

View File

@@ -99,16 +99,27 @@ class Logger implements LoggerInterface
*
* @var array of Monolog\Handler\HandlerInterface
*/
protected $handlers = array();
protected $processors = array();
protected $handlers;
/**
* @param string $name The logging channel
* Processors that will process all log records
*
* To process records of a single handler instead, add the processor on that specific handler
*
* @var array of callables
*/
public function __construct($name)
protected $processors;
/**
* @param string $name The logging channel
* @param array $handlers Optional stack of handlers, the first one in the array is called first, etc.
* @param array $processors Optional array of processors
*/
public function __construct($name, array $handlers = array(), array $processors = array())
{
$this->name = $name;
$this->handlers = $handlers;
$this->processors = $processors;
}
/**

View File

@@ -85,6 +85,26 @@ class LoggerTest extends \PHPUnit_Framework_TestCase
$this->assertFalse($logger->addWarning('test'));
}
public function testHandlersInCtor()
{
$handler1 = new TestHandler;
$handler2 = new TestHandler;
$logger = new Logger(__METHOD__, array($handler1, $handler2));
$this->assertEquals($handler1, $logger->popHandler());
$this->assertEquals($handler2, $logger->popHandler());
}
public function testProcessorsInCtor()
{
$processor1 = new WebProcessor;
$processor2 = new WebProcessor;
$logger = new Logger(__METHOD__, array(), array($processor1, $processor2));
$this->assertEquals($processor1, $logger->popProcessor());
$this->assertEquals($processor2, $logger->popProcessor());
}
/**
* @covers Monolog\Logger::pushHandler
* @covers Monolog\Logger::popHandler