mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-04 12:17:35 +02:00
@@ -129,6 +129,15 @@ class RavenHandler extends AbstractProcessingHandler
|
|||||||
{
|
{
|
||||||
$options = array();
|
$options = array();
|
||||||
$options['level'] = $this->logLevels[$record['level']];
|
$options['level'] = $this->logLevels[$record['level']];
|
||||||
|
$options['tags'] = array();
|
||||||
|
if (!empty($record['extra']['tags'])) {
|
||||||
|
$options['tags'] = array_merge($options['tags'], $record['extra']['tags']);
|
||||||
|
unset($record['extra']['tags']);
|
||||||
|
}
|
||||||
|
if (!empty($record['context']['tags'])) {
|
||||||
|
$options['tags'] = array_merge($options['tags'], $record['context']['tags']);
|
||||||
|
unset($record['context']['tags']);
|
||||||
|
}
|
||||||
if (!empty($record['context'])) {
|
if (!empty($record['context'])) {
|
||||||
$options['extra']['context'] = $record['context'];
|
$options['extra']['context'] = $record['context'];
|
||||||
}
|
}
|
||||||
|
34
src/Monolog/Processor/TagProcessor.php
Normal file
34
src/Monolog/Processor/TagProcessor.php
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
<?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\Processor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a tags array into record
|
||||||
|
*
|
||||||
|
* @author Martijn Riemers
|
||||||
|
*/
|
||||||
|
class TagProcessor
|
||||||
|
{
|
||||||
|
private $tags;
|
||||||
|
|
||||||
|
public function __construct(array $tags = array())
|
||||||
|
{
|
||||||
|
$this->tags = $tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __invoke(array $record)
|
||||||
|
{
|
||||||
|
$record['extra']['tags'] = $this->tags;
|
||||||
|
|
||||||
|
return $record;
|
||||||
|
}
|
||||||
|
}
|
@@ -72,6 +72,18 @@ class RavenHandlerTest extends TestCase
|
|||||||
$this->assertEquals($ravenClient::WARNING, $ravenClient->lastData['level']);
|
$this->assertEquals($ravenClient::WARNING, $ravenClient->lastData['level']);
|
||||||
$this->assertContains($record['message'], $ravenClient->lastData['message']);
|
$this->assertContains($record['message'], $ravenClient->lastData['message']);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testTag()
|
||||||
|
{
|
||||||
|
$ravenClient = $this->getRavenClient();
|
||||||
|
$handler = $this->getHandler($ravenClient);
|
||||||
|
|
||||||
|
$tags = array(1, 2, 'foo');
|
||||||
|
$record = $this->getRecord(Logger::INFO, "test", array('tags' => $tags));
|
||||||
|
$handler->handle($record);
|
||||||
|
|
||||||
|
$this->assertEquals($tags, $ravenClient->lastData['tags']);
|
||||||
|
}
|
||||||
|
|
||||||
public function testException()
|
public function testException()
|
||||||
{
|
{
|
||||||
|
29
tests/Monolog/Processor/TagProcessorTest.php
Normal file
29
tests/Monolog/Processor/TagProcessorTest.php
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
<?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\Processor;
|
||||||
|
|
||||||
|
use Monolog\TestCase;
|
||||||
|
|
||||||
|
class TagProcessorTest extends TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @covers Monolog\Processor\TagProcessor::__invoke
|
||||||
|
*/
|
||||||
|
public function testProcessor()
|
||||||
|
{
|
||||||
|
$tags = array(1, 2, 3);
|
||||||
|
$processor = new TagProcessor($tags);
|
||||||
|
$record = $processor($this->getRecord());
|
||||||
|
|
||||||
|
$this->assertEquals($tags, $record['extra']['tags']);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user