summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/Monolog/Formatter/NormalizerFormatter.php18
-rw-r--r--tests/Monolog/Formatter/ElasticaFormatterTest.php2
-rw-r--r--tests/Monolog/Formatter/LineFormatterTest.php4
-rw-r--r--tests/Monolog/Formatter/NormalizerFormatterTest.php14
-rw-r--r--tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php2
5 files changed, 23 insertions, 17 deletions
diff --git a/src/Monolog/Formatter/NormalizerFormatter.php b/src/Monolog/Formatter/NormalizerFormatter.php
index bd524bd..8e0e7a5 100644
--- a/src/Monolog/Formatter/NormalizerFormatter.php
+++ b/src/Monolog/Formatter/NormalizerFormatter.php
@@ -98,19 +98,25 @@ class NormalizerFormatter implements FormatterInterface
return $this->normalizeException($data);
}
- // non-serializable objects that implement __toString stringified
- if (method_exists($data, '__toString') && !$data instanceof \JsonSerializable) {
+ if ($data instanceof \JsonSerializable) {
+ $value = $data->jsonSerialize();
+ } elseif (method_exists($data, '__toString')) {
$value = $data->__toString();
} else {
- // the rest is json-serialized in some way
- $value = $this->toJson($data, true);
+ // the rest is normalized by json encoding and decoding it
+ $encoded = $this->toJson($data, true);
+ if ($encoded === false) {
+ $value = 'JSON_ERROR';
+ } else {
+ $value = json_decode($encoded, true);
+ }
}
- return sprintf("[object] (%s: %s)", get_class($data), $value);
+ return [get_class($data) => $value];
}
if (is_resource($data)) {
- return sprintf('[resource] (%s)', get_resource_type($data));
+ return sprintf('[resource(%s)]', get_resource_type($data));
}
return '[unknown('.gettype($data).')]';
diff --git a/tests/Monolog/Formatter/ElasticaFormatterTest.php b/tests/Monolog/Formatter/ElasticaFormatterTest.php
index 428c27b..9ad94fe 100644
--- a/tests/Monolog/Formatter/ElasticaFormatterTest.php
+++ b/tests/Monolog/Formatter/ElasticaFormatterTest.php
@@ -44,7 +44,7 @@ class ElasticaFormatterTest extends \PHPUnit_Framework_TestCase
$expected = $msg;
$expected['datetime'] = '1970-01-01T00:00:00.000000+00:00';
$expected['context'] = array(
- 'class' => '[object] (stdClass: {})',
+ 'class' => ['stdClass' => []],
'foo' => 7,
0 => 'bar',
);
diff --git a/tests/Monolog/Formatter/LineFormatterTest.php b/tests/Monolog/Formatter/LineFormatterTest.php
index 397c7f6..67670d4 100644
--- a/tests/Monolog/Formatter/LineFormatterTest.php
+++ b/tests/Monolog/Formatter/LineFormatterTest.php
@@ -117,7 +117,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: bar)","baz":[],"res":"[resource] (stream)"}'."\n", $message);
+ $this->assertEquals('['.date('Y-m-d').'] meh.ERROR: foobar [] {"foo":{"Monolog\\\\Formatter\\\\TestFoo":{"foo":"fooValue"}},"bar":{"Monolog\\\\Formatter\\\\TestBar":"bar"},"baz":[],"res":"[resource(stream)]"}'."\n", $message);
}
public function testDefFormatWithException()
@@ -210,7 +210,7 @@ class LineFormatterTest extends \PHPUnit_Framework_TestCase
class TestFoo
{
- public $foo = 'foo';
+ public $foo = 'fooValue';
}
class TestBar
diff --git a/tests/Monolog/Formatter/NormalizerFormatterTest.php b/tests/Monolog/Formatter/NormalizerFormatterTest.php
index c689266..ff481c7 100644
--- a/tests/Monolog/Formatter/NormalizerFormatterTest.php
+++ b/tests/Monolog/Formatter/NormalizerFormatterTest.php
@@ -47,10 +47,10 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
'message' => 'foo',
'datetime' => date('Y-m-d'),
'extra' => array(
- 'foo' => '[object] (Monolog\\Formatter\\TestFooNorm: {"foo":"foo"})',
- 'bar' => '[object] (Monolog\\Formatter\\TestBarNorm: bar)',
+ 'foo' => ['Monolog\\Formatter\\TestFooNorm' => ["foo" => "fooValue"]],
+ 'bar' => ['Monolog\\Formatter\\TestBarNorm' => 'bar'],
'baz' => array(),
- 'res' => '[resource] (stream)',
+ 'res' => '[resource(stream)]',
),
'context' => array(
'foo' => 'bar',
@@ -293,7 +293,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
$wrappedResource->foo = $resource;
// Just do something stupid with a resource/wrapped resource as argument
array_keys($wrappedResource);
- } catch (\Exception $e) {
+ } catch (\Throwable $e) {
restore_error_handler();
}
@@ -302,11 +302,11 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
$result = $formatter->format($record);
$this->assertRegExp(
- '%"resource":"\[resource\] \(stream\)"%',
+ '%"resource":"\[resource\(stream\)\]"%',
$result['context']['exception']['trace'][0]
);
- $pattern = '%"wrappedResource":"\[object\] \(Monolog\\\\\\\\Formatter\\\\\\\\TestFooNorm: \)"%';
+ $pattern = '%"wrappedResource":\{"Monolog\\\\\\\\Formatter\\\\\\\\TestFooNorm":"JSON_ERROR"\}%';
// Tests that the wrapped resource is ignored while encoding, only works for PHP <= 5.4
$this->assertRegExp(
@@ -318,7 +318,7 @@ class NormalizerFormatterTest extends \PHPUnit_Framework_TestCase
class TestFooNorm
{
- public $foo = 'foo';
+ public $foo = 'fooValue';
}
class TestBarNorm
diff --git a/tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php b/tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php
index 3383381..5718c41 100644
--- a/tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php
+++ b/tests/Monolog/Handler/DoctrineCouchDBHandlerTest.php
@@ -34,7 +34,7 @@ class DoctrineCouchDBHandlerTest extends TestCase
$expected = array(
'message' => 'test',
- 'context' => array('data' => '[object] (stdClass: {})', 'foo' => 34),
+ 'context' => array('data' => ['stdClass' => []], 'foo' => 34),
'level' => Logger::WARNING,
'level_name' => 'WARNING',
'channel' => 'test',