mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-08 06:06:40 +02:00
Add INF/NaN normalization, fixes #523
This commit is contained in:
@@ -58,6 +58,15 @@ class NormalizerFormatter implements FormatterInterface
|
|||||||
protected function normalize($data)
|
protected function normalize($data)
|
||||||
{
|
{
|
||||||
if (null === $data || is_scalar($data)) {
|
if (null === $data || is_scalar($data)) {
|
||||||
|
if (is_float($data)) {
|
||||||
|
if (is_infinite($data)) {
|
||||||
|
return ($data > 0 ? '' : '-') . 'INF';
|
||||||
|
}
|
||||||
|
if (is_nan($data)) {
|
||||||
|
return 'NaN';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return $data;
|
return $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -28,6 +28,9 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
'context' => array(
|
'context' => array(
|
||||||
'foo' => 'bar',
|
'foo' => 'bar',
|
||||||
'baz' => 'qux',
|
'baz' => 'qux',
|
||||||
|
'inf' => INF,
|
||||||
|
'-inf' => -INF,
|
||||||
|
'nan' => acos(4),
|
||||||
),
|
),
|
||||||
));
|
));
|
||||||
|
|
||||||
@@ -45,6 +48,9 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
|||||||
'context' => array(
|
'context' => array(
|
||||||
'foo' => 'bar',
|
'foo' => 'bar',
|
||||||
'baz' => 'qux',
|
'baz' => 'qux',
|
||||||
|
'inf' => 'INF',
|
||||||
|
'-inf' => '-INF',
|
||||||
|
'nan' => 'NaN',
|
||||||
)
|
)
|
||||||
), $formatted);
|
), $formatted);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user