1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-05 12:47:39 +02:00

Add total amount of items when aborting traversable normalization

This commit is contained in:
Jordi Boggiano
2016-10-03 20:31:30 +02:00
parent 7f135e9ed0
commit 214b8ef34b
2 changed files with 19 additions and 1 deletions

View File

@@ -80,7 +80,7 @@ class NormalizerFormatter implements FormatterInterface
foreach ($data as $key => $value) {
if ($count++ >= 1000) {
$normalized['...'] = 'Over 1000 items, aborting normalization';
$normalized['...'] = 'Over 1000 items ('.($data instanceof \Generator ? 'generator function' : count($data).' total').'), aborting normalization';
break;
}
$normalized[$key] = $this->normalize($value);

View File

@@ -217,6 +217,24 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(@json_encode(array($resource)), $res);
}
public function testNormalizeHandleLargeArrays()
{
$formatter = new NormalizerFormatter();
$largeArray = range(1, 2000);
$res = $formatter->format(array(
'level_name' => 'CRITICAL',
'channel' => 'test',
'message' => 'bar',
'context' => array($largeArray),
'datetime' => new \DateTime,
'extra' => array(),
));
$this->assertCount(1000, $res['context'][0]);
$this->assertEquals('Over 1000 items (2000 total), aborting normalization', $res['context'][0]['...']);
}
/**
* @expectedException RuntimeException
*/