mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-10 23:24:02 +02:00
Allow JsonFormatter maximum normalized depth and maximum number of items per level to be configured in the constructor.
This commit is contained in:
@@ -110,6 +110,47 @@ class JsonFormatterTest extends TestCase
|
||||
$this->assertContextContainsFormattedException($formattedThrowable, $message);
|
||||
}
|
||||
|
||||
public function testMaxNormalizeDepth()
|
||||
{
|
||||
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, true);
|
||||
$formatter->setMaxNormalizeDepth(1);
|
||||
$throwable = new \Error('Foo');
|
||||
|
||||
$message = $this->formatRecordWithExceptionInContext($formatter, $throwable);
|
||||
|
||||
$this->assertContextContainsFormattedException('"Over 1 levels deep, aborting normalization"', $message);
|
||||
}
|
||||
|
||||
public function testMaxNormalizeItemCountWith0ItemsMax()
|
||||
{
|
||||
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, true);
|
||||
$formatter->setMaxNormalizeDepth(9);
|
||||
$formatter->setMaxNormalizeItemCount(0);
|
||||
$throwable = new \Error('Foo');
|
||||
|
||||
$message = $this->formatRecordWithExceptionInContext($formatter, $throwable);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"...":"Over 0 items, aborting normalization"}'."\n",
|
||||
$message
|
||||
);
|
||||
}
|
||||
|
||||
public function testMaxNormalizeItemCountWith3ItemsMax()
|
||||
{
|
||||
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, true);
|
||||
$formatter->setMaxNormalizeDepth(9);
|
||||
$formatter->setMaxNormalizeItemCount(3);
|
||||
$throwable = new \Error('Foo');
|
||||
|
||||
$message = $this->formatRecordWithExceptionInContext($formatter, $throwable);
|
||||
|
||||
$this->assertEquals(
|
||||
'{"level_name":"CRITICAL","channel":"core","...":"Over 3 items, aborting normalization"}'."\n",
|
||||
$message
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $expected
|
||||
* @param string $actual
|
||||
|
Reference in New Issue
Block a user