1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-06 13:16:39 +02:00

Merge branch '1.x'

This commit is contained in:
Jordi Boggiano
2019-11-13 10:58:42 +01:00
6 changed files with 59 additions and 23 deletions

View File

@@ -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 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. * 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 * 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 * 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) ### 1.25.1 (2019-09-06)
* Fixed forward-compatible interfaces to be compatible with Monolog 1.x too. * Fixed forward-compatible interfaces to be compatible with Monolog 1.x too.

View File

@@ -130,4 +130,22 @@ class BufferHandler extends AbstractHandler implements ProcessableHandlerInterfa
$this->handler->reset(); $this->handler->reset();
} }
} }
/**
* {@inheritdoc}
*/
public function setFormatter(FormatterInterface $formatter)
{
$this->handler->setFormatter($formatter);
return $this;
}
/**
* {@inheritdoc}
*/
public function getFormatter()
{
return $this->handler->getFormatter();
}
} }

View File

@@ -217,8 +217,8 @@ class SlackRecord
$hasNonNumericKeys = !count(array_filter(array_keys($normalized), 'is_numeric')); $hasNonNumericKeys = !count(array_filter(array_keys($normalized), 'is_numeric'));
return $hasSecondDimension || $hasNonNumericKeys return $hasSecondDimension || $hasNonNumericKeys
? Utils::jsonEncode($normalized, JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE) ? Utils::jsonEncode($normalized, JSON_PRETTY_PRINT|Utils::DEFAULT_JSON_FLAGS)
: Utils::jsonEncode($normalized, JSON_UNESCAPED_UNICODE); : Utils::jsonEncode($normalized, Utils::DEFAULT_JSON_FLAGS);
} }
/** /**

View File

@@ -49,13 +49,17 @@ final class Utils
$encodeFlags = self::DEFAULT_JSON_FLAGS; $encodeFlags = self::DEFAULT_JSON_FLAGS;
} }
$json = json_encode($data, $encodeFlags); if ($ignoreErrors) {
$json = @json_encode($data, $encodeFlags);
if (false === $json) { if (false === $json) {
if ($ignoreErrors) {
return 'null'; return 'null';
} }
return $json;
}
$json = json_encode($data, $encodeFlags);
if (false === $json) {
$json = self::handleJsonError(json_last_error(), $data); $json = self::handleJsonError(json_last_error(), $data);
} }

View File

@@ -188,7 +188,11 @@ class NormalizerFormatterTest extends TestCase
restore_error_handler(); 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() public function testCanNormalizeReferences()
@@ -223,7 +227,11 @@ class NormalizerFormatterTest extends TestCase
restore_error_handler(); restore_error_handler();
$this->assertEquals('null', $res); if (PHP_VERSION_ID < 50500) {
$this->assertEquals('[null]', $res);
} else {
$this->assertEquals('null', $res);
}
} }
public function testNormalizeHandleLargeArraysWithExactly1000Items() public function testNormalizeHandleLargeArraysWithExactly1000Items()

View File

@@ -19,13 +19,6 @@ use Monolog\Test\TestCase;
*/ */
class SlackRecordTest extends TestCase class SlackRecordTest extends TestCase
{ {
private $jsonPrettyPrintFlag;
protected function setUp(): void
{
$this->jsonPrettyPrintFlag = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 128;
}
public function dataGetAttachmentColor() public function dataGetAttachmentColor()
{ {
return array( return array(
@@ -78,16 +71,14 @@ class SlackRecordTest extends TestCase
*/ */
public function dataStringify() public function dataStringify()
{ {
$jsonPrettyPrintFlag = defined('JSON_PRETTY_PRINT') ? JSON_PRETTY_PRINT : 128;
$multipleDimensions = array(array(1, 2)); $multipleDimensions = array(array(1, 2));
$numericKeys = array('library' => 'monolog'); $numericKeys = array('library' => 'monolog');
$singleDimension = array(1, 'Hello', 'Jordi'); $singleDimension = array(1, 'Hello', 'Jordi');
return array( return array(
array(array(), '[]'), array(array(), '[]'),
array($multipleDimensions, json_encode($multipleDimensions, $jsonPrettyPrintFlag)), array($multipleDimensions, json_encode($multipleDimensions, JSON_PRETTY_PRINT)),
array($numericKeys, json_encode($numericKeys, $jsonPrettyPrintFlag)), array($numericKeys, json_encode($numericKeys, JSON_PRETTY_PRINT)),
array($singleDimension, json_encode($singleDimension)), array($singleDimension, json_encode($singleDimension)),
); );
} }
@@ -271,12 +262,12 @@ class SlackRecordTest extends TestCase
array( array(
array( array(
'title' => 'Extra', 'title' => 'Extra',
'value' => sprintf('```%s```', json_encode($extra, $this->jsonPrettyPrintFlag)), 'value' => sprintf('```%s```', json_encode($extra, JSON_PRETTY_PRINT)),
'short' => false, 'short' => false,
), ),
array( array(
'title' => 'Context', 'title' => 'Context',
'value' => sprintf('```%s```', json_encode($context, $this->jsonPrettyPrintFlag)), 'value' => sprintf('```%s```', json_encode($context, JSON_PRETTY_PRINT)),
'short' => false, 'short' => false,
), ),
), ),
@@ -381,7 +372,7 @@ class SlackRecordTest extends TestCase
$expected = array( $expected = array(
array( array(
'title' => 'Info', '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, 'short' => false,
), ),
array( array(