diff --git a/src/Monolog/Logger.php b/src/Monolog/Logger.php index fab66885..78406e2d 100644 --- a/src/Monolog/Logger.php +++ b/src/Monolog/Logger.php @@ -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; } /** diff --git a/tests/Monolog/LoggerTest.php b/tests/Monolog/LoggerTest.php index fafe951f..8bcbbf90 100644 --- a/tests/Monolog/LoggerTest.php +++ b/tests/Monolog/LoggerTest.php @@ -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