diff --git a/CHANGELOG.md b/CHANGELOG.md index d090053b..52191a8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ -### 2.0.1 (xx) +### 2.0.1 (2019-11-13) + * Fixed normalization of Traversables to avoid traversing them as not all of them are rewindable + * Fixed setFormatter/getFormatter to forward to the nested handler in FilterHandler, FingersCrossedHandler, BufferHandler and SamplingHandler + * Fixed BrowserConsoleHandler formatting when using multiple styles + * Fixed normalization of exception codes to be always integers even for PDOException which have them as numeric strings + * Fixed normalization of SoapFault objects containing non-strings as "detail" + * Fixed json encoding across all handlers to always attempt recovery of non-UTF-8 strings instead of failing the whole encoding * Fixed ChromePHPHandler to avoid sending more data than latest Chrome versions allow in headers (4KB down from 256KB). * Fixed type error in BrowserConsoleHandler when the context array of log records was not associative. @@ -52,6 +58,15 @@ * Added support for the PHP 7.x `mongodb` extension in the MongoDBHandler * Fixed many minor issues in various handlers, and probably added a few regressions too +### 1.25.2 (2019-11-13) + + * Fixed normalization of Traversables to avoid traversing them as not all of them are rewindable + * Fixed setFormatter/getFormatter to forward to the nested handler in FilterHandler, FingersCrossedHandler, BufferHandler and SamplingHandler + * Fixed BrowserConsoleHandler formatting when using multiple styles + * Fixed normalization of exception codes to be always integers even for PDOException which have them as numeric strings + * Fixed normalization of SoapFault objects containing non-strings as "detail" + * Fixed json encoding across all handlers to always attempt recovery of non-UTF-8 strings instead of failing the whole encoding + ### 1.25.1 (2019-09-06) * Fixed forward-compatible interfaces to be compatible with Monolog 1.x too. diff --git a/src/Monolog/Handler/BufferHandler.php b/src/Monolog/Handler/BufferHandler.php index d9505b79..a2515b64 100644 --- a/src/Monolog/Handler/BufferHandler.php +++ b/src/Monolog/Handler/BufferHandler.php @@ -130,4 +130,22 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa $this->handler->reset(); } } + + /** + * {@inheritdoc} + */ + public function setFormatter(FormatterInterface $formatter) + { + $this->handler->setFormatter($formatter); + + return $this; + } + + /** + * {@inheritdoc} + */ + public function getFormatter() + { + return $this->handler->getFormatter(); + } } diff --git a/src/Monolog/Handler/Slack/SlackRecord.php b/src/Monolog/Handler/Slack/SlackRecord.php index 60d2c9e1..b74a22fb 100644 --- a/src/Monolog/Handler/Slack/SlackRecord.php +++ b/src/Monolog/Handler/Slack/SlackRecord.php @@ -217,8 +217,8 @@ class SlackRecord $hasNonNumericKeys = !count(array_filter(array_keys($normalized), 'is_numeric')); return $hasSecondDimension || $hasNonNumericKeys - ? Utils::jsonEncode($normalized, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE) - : Utils::jsonEncode($normalized, JSON_UNESCAPED_UNICODE); + ? Utils::jsonEncode($normalized, JSON_PRETTY_PRINT|Utils::DEFAULT_JSON_FLAGS) + : Utils::jsonEncode($normalized, Utils::DEFAULT_JSON_FLAGS); } /** diff --git a/src/Monolog/Utils.php b/src/Monolog/Utils.php index 6af709c5..358087cb 100644 --- a/src/Monolog/Utils.php +++ b/src/Monolog/Utils.php @@ -49,13 +49,17 @@ final class Utils $encodeFlags = self::DEFAULT_JSON_FLAGS; } - $json = json_encode($data, $encodeFlags); - - if (false === $json) { - if ($ignoreErrors) { + if ($ignoreErrors) { + $json = @json_encode($data, $encodeFlags); + if (false === $json) { return 'null'; } + return $json; + } + + $json = json_encode($data, $encodeFlags); + if (false === $json) { $json = self::handleJsonError(json_last_error(), $data); } diff --git a/tests/Monolog/Formatter/NormalizerFormatterTest.php b/tests/Monolog/Formatter/NormalizerFormatterTest.php index d077d687..d3661c5a 100644 --- a/tests/Monolog/Formatter/NormalizerFormatterTest.php +++ b/tests/Monolog/Formatter/NormalizerFormatterTest.php @@ -188,7 +188,11 @@ class NormalizerFormatterTest extends TestCase restore_error_handler(); - $this->assertEquals('null', $res); + if (PHP_VERSION_ID < 50500) { + $this->assertEquals('[{"bar":{"foo":null}},{"foo":{"bar":null}}]', $res); + } else { + $this->assertEquals('null', $res); + } } public function testCanNormalizeReferences() @@ -223,7 +227,11 @@ class NormalizerFormatterTest extends TestCase restore_error_handler(); - $this->assertEquals('null', $res); + if (PHP_VERSION_ID < 50500) { + $this->assertEquals('[null]', $res); + } else { + $this->assertEquals('null', $res); + } } public function testNormalizeHandleLargeArraysWithExactly1000Items() diff --git a/tests/Monolog/Handler/Slack/SlackRecordTest.php b/tests/Monolog/Handler/Slack/SlackRecordTest.php index f1572b27..10738955 100644 --- a/tests/Monolog/Handler/Slack/SlackRecordTest.php +++ b/tests/Monolog/Handler/Slack/SlackRecordTest.php @@ -19,13 +19,6 @@ use Monolog\Test\TestCase; */ class SlackRecordTest extends TestCase { - private $jsonPrettyPrintFlag; - - protected function setUp(): void - { - $this->jsonPrettyPrintFlag = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 128; - } - public function dataGetAttachmentColor() { return array( @@ -78,16 +71,14 @@ class SlackRecordTest extends TestCase */ public function dataStringify() { - $jsonPrettyPrintFlag = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 128; - $multipleDimensions = array(array(1, 2)); $numericKeys = array('library' => 'monolog'); $singleDimension = array(1, 'Hello', 'Jordi'); return array( array(array(), '[]'), - array($multipleDimensions, json_encode($multipleDimensions, $jsonPrettyPrintFlag)), - array($numericKeys, json_encode($numericKeys, $jsonPrettyPrintFlag)), + array($multipleDimensions, json_encode($multipleDimensions, JSON_PRETTY_PRINT)), + array($numericKeys, json_encode($numericKeys, JSON_PRETTY_PRINT)), array($singleDimension, json_encode($singleDimension)), ); } @@ -271,12 +262,12 @@ class SlackRecordTest extends TestCase array( array( 'title' => 'Extra', - 'value' => sprintf('```%s```', json_encode($extra, $this->jsonPrettyPrintFlag)), + 'value' => sprintf('```%s```', json_encode($extra, JSON_PRETTY_PRINT)), 'short' => false, ), array( 'title' => 'Context', - 'value' => sprintf('```%s```', json_encode($context, $this->jsonPrettyPrintFlag)), + 'value' => sprintf('```%s```', json_encode($context, JSON_PRETTY_PRINT)), 'short' => false, ), ), @@ -381,7 +372,7 @@ class SlackRecordTest extends TestCase $expected = array( array( 'title' => 'Info', - 'value' => sprintf('```%s```', json_encode(array('author' => 'Jordi'), $this->jsonPrettyPrintFlag)), + 'value' => sprintf('```%s```', json_encode(array('author' => 'Jordi'), JSON_PRETTY_PRINT)), 'short' => false, ), array(