1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-07 21:56:31 +02:00

Add INF/NaN normalization, fixes #523

This commit is contained in:
Jordi Boggiano
2015-03-05 00:57:49 +00:00
parent 4a794ed5f8
commit d434bb4794
2 changed files with 15 additions and 0 deletions

View File

@@ -58,6 +58,15 @@ class NormalizerFormatter implements FormatterInterface
protected function normalize($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;
}

View File

@@ -28,6 +28,9 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
'context' => array(
'foo' => 'bar',
'baz' => 'qux',
'inf' => INF,
'-inf' => -INF,
'nan' => acos(4),
),
));
@@ -45,6 +48,9 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
'context' => array(
'foo' => 'bar',
'baz' => 'qux',
'inf' => 'INF',
'-inf' => '-INF',
'nan' => 'NaN',
)
), $formatted);
}