diff --git a/CHANGELOG.md b/CHANGELOG.md index e0bb7ab8..d78779a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * Added support for RFC3164 (outdated BSD syslog protocol) to SyslogUdpHandler * Fixed issue in GroupHandler and WhatFailureGroupHandler where setting multiple processors would duplicate records * Fixed issue in SignalHandler restarting syscalls functionality + * Fixed normalizers handling of exception backtraces to avoid serializing arguments in some cases * Fixed ZendMonitorHandler to work with the latest Zend Server versions ### 1.24.0 (2018-11-05) diff --git a/src/Monolog/Formatter/JsonFormatter.php b/src/Monolog/Formatter/JsonFormatter.php index 9bd305f2..2ff119ea 100644 --- a/src/Monolog/Formatter/JsonFormatter.php +++ b/src/Monolog/Formatter/JsonFormatter.php @@ -195,12 +195,6 @@ class JsonFormatter extends NormalizerFormatter foreach ($trace as $frame) { if (isset($frame['file'])) { $data['trace'][] = $frame['file'].':'.$frame['line']; - } elseif (isset($frame['function']) && $frame['function'] === '{closure}') { - // We should again normalize the frames, because it might contain invalid items - $data['trace'][] = $frame['function']; - } else { - // We should again normalize the frames, because it might contain invalid items - $data['trace'][] = $this->normalize($frame); } } } diff --git a/src/Monolog/Formatter/NormalizerFormatter.php b/src/Monolog/Formatter/NormalizerFormatter.php index 66866578..9865394e 100644 --- a/src/Monolog/Formatter/NormalizerFormatter.php +++ b/src/Monolog/Formatter/NormalizerFormatter.php @@ -151,23 +151,6 @@ class NormalizerFormatter implements FormatterInterface foreach ($trace as $frame) { if (isset($frame['file'])) { $data['trace'][] = $frame['file'].':'.$frame['line']; - } elseif (isset($frame['function']) && $frame['function'] === '{closure}') { - // Simplify closures handling - $data['trace'][] = $frame['function']; - } else { - if (isset($frame['args'])) { - // Make sure that objects present as arguments are not serialized nicely but rather only - // as a class name to avoid any unexpected leak of sensitive information - $frame['args'] = array_map(function ($arg) { - if (is_object($arg) && !($arg instanceof \DateTime || $arg instanceof \DateTimeInterface)) { - return sprintf("[object] (%s)", Utils::getClass($arg)); - } - - return $arg; - }, $frame['args']); - } - // We should again normalize the frames, because it might contain invalid items - $data['trace'][] = $this->toJson($this->normalize($frame), true); } } diff --git a/tests/Monolog/Formatter/NormalizerFormatterTest.php b/tests/Monolog/Formatter/NormalizerFormatterTest.php index bafd1c74..d4e0d98d 100644 --- a/tests/Monolog/Formatter/NormalizerFormatterTest.php +++ b/tests/Monolog/Formatter/NormalizerFormatterTest.php @@ -390,20 +390,8 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase $record = array('context' => array('exception' => $e)); $result = $formatter->format($record); - $this->assertRegExp( - '%"resource":"\[resource\] \(stream\)"%', - $result['context']['exception']['trace'][0] - ); - - if (version_compare(PHP_VERSION, '5.5.0', '>=')) { - $pattern = '%"wrappedResource":"\[object\] \(Monolog\\\\\\\\Formatter\\\\\\\\TestFooNorm: \)"%'; - } else { - $pattern = '%\\\\"foo\\\\":null%'; - } - - // Tests that the wrapped resource is ignored while encoding, only works for PHP <= 5.4 - $this->assertRegExp( - $pattern, + $this->assertSame( + __FILE__.':'.(__LINE__-10), $result['context']['exception']['trace'][0] ); } @@ -421,7 +409,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase $result = $formatter->format($record); $this->assertSame( - '{"function":"throwHelper","class":"Monolog\\\\Formatter\\\\NormalizerFormatterTest","type":"->","args":["[object] (Monolog\\\\Formatter\\\\TestInfoLeak)","'.$dt->format('Y-m-d H:i:s').'"]}', + __FILE__ .':'.(__LINE__-9), $result['context']['exception']['trace'][0] ); } diff --git a/tests/Monolog/Formatter/ScalarFormatterTest.php b/tests/Monolog/Formatter/ScalarFormatterTest.php index b1c8fd49..2d7e6340 100644 --- a/tests/Monolog/Formatter/ScalarFormatterTest.php +++ b/tests/Monolog/Formatter/ScalarFormatterTest.php @@ -27,8 +27,6 @@ class ScalarFormatterTest extends \PHPUnit_Framework_TestCase foreach ($trace as $frame) { if (isset($frame['file'])) { $data[] = $frame['file'].':'.$frame['line']; - } else { - $data[] = json_encode($frame); } }