mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-05 04:37:38 +02:00
Fix up #546 to json serialize correctly
This commit is contained in:
@@ -94,12 +94,15 @@ class NormalizerFormatter implements FormatterInterface
|
||||
return $this->normalizeException($data);
|
||||
}
|
||||
|
||||
$objData = $this->toJson($data, true);;
|
||||
if(!$objData and method_exists($data, '__toString')) {
|
||||
$objData = $data;
|
||||
// non-serializable objects that implement __toString stringified
|
||||
if (method_exists($data, '__toString') && !$data instanceof \JsonSerializable) {
|
||||
$value = (string) $data;
|
||||
} else {
|
||||
// the rest is json-serialized in some way
|
||||
$value = $this->toJson($data, true);
|
||||
}
|
||||
|
||||
return sprintf("[object] (%s: %s)", get_class($data), $objData);
|
||||
return sprintf("[object] (%s: %s)", get_class($data), $value);
|
||||
}
|
||||
|
||||
if (is_resource($data)) {
|
||||
|
@@ -103,7 +103,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
'message' => 'foobar',
|
||||
));
|
||||
|
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\\\Formatter\\\\TestFoo: {\\"foo\\":\\"foo\\"})","bar":"[object] (Monolog\\\\Formatter\\\\TestBar: {})","baz":[],"res":"[resource]"}'."\n", $message);
|
||||
$this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foobar [] {"foo":"[object] (Monolog\\\\Formatter\\\\TestFoo: {\\"foo\\":\\"foo\\"})","bar":"[object] (Monolog\\\\Formatter\\\\TestBar: bar)","baz":[],"res":"[resource]"}'."\n", $message);
|
||||
}
|
||||
|
||||
public function testDefFormatWithException()
|
||||
|
@@ -41,7 +41,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
'datetime' => date('Y-m-d'),
|
||||
'extra' => array(
|
||||
'foo' => '[object] (Monolog\\Formatter\\TestFooNorm: {"foo":"foo"})',
|
||||
'bar' => '[object] (Monolog\\Formatter\\TestBarNorm: {})',
|
||||
'bar' => '[object] (Monolog\\Formatter\\TestBarNorm: bar)',
|
||||
'baz' => array(),
|
||||
'res' => '[resource]',
|
||||
),
|
||||
|
Reference in New Issue
Block a user