diff --git a/src/Monolog/Processor/TagProcessor.php b/src/Monolog/Processor/TagProcessor.php index 2784cef4..2b6212e2 100644 --- a/src/Monolog/Processor/TagProcessor.php +++ b/src/Monolog/Processor/TagProcessor.php @@ -21,6 +21,16 @@ class TagProcessor private $tags; public function __construct(array $tags = array()) + { + $this->setTags($tags); + } + + public function addTags(array $tags = array()) + { + $this->tags = array_values(array_unique(array_merge($this->tags, $tags))); + } + + public function setTags(array $tags = array()) { $this->tags = $tags; } diff --git a/tests/Monolog/Processor/TagProcessorTest.php b/tests/Monolog/Processor/TagProcessorTest.php index 851a9dc2..bf1659c5 100644 --- a/tests/Monolog/Processor/TagProcessorTest.php +++ b/tests/Monolog/Processor/TagProcessorTest.php @@ -26,4 +26,24 @@ class TagProcessorTest extends TestCase $this->assertEquals($tags, $record['extra']['tags']); } + + /** + * @covers Monolog\Processor\TagProcessor::__invoke + */ + public function testProcessorTagModification() + { + $tags = array(1, 2, 3); + $processor = new TagProcessor($tags); + + $record = $processor($this->getRecord()); + $this->assertEquals($tags, $record['extra']['tags']); + + $processor->setTags(array('a', 'b')); + $record = $processor($this->getRecord()); + $this->assertEquals(array('a', 'b'), $record['extra']['tags']); + + $processor->addTags(array('a', 'c')); + $record = $processor($this->getRecord()); + $this->assertEquals(array('a', 'b', 'c'), $record['extra']['tags']); + } }