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

Merge branch '2.x'

This commit is contained in:
Jordi Boggiano
2022-07-22 15:51:15 +02:00
21 changed files with 181 additions and 42 deletions

View File

@@ -13,6 +13,7 @@ namespace Monolog\Formatter;
use Monolog\Level;
use Monolog\LogRecord;
use JsonSerializable;
use Monolog\Test\TestCase;
class JsonFormatterTest extends TestCase
@@ -289,4 +290,58 @@ class JsonFormatterTest extends TestCase
$record
);
}
public function testFormatObjects()
{
$formatter = new JsonFormatter();
$record = $formatter->format($this->getRecord(
Level::Debug,
'Testing',
channel: 'test',
datetime: new \DateTimeImmutable('2022-02-22 00:00:00'),
context: [
'public' => new TestJsonNormPublic,
'private' => new TestJsonNormPrivate,
'withToStringAndJson' => new TestJsonNormWithToStringAndJson,
'withToString' => new TestJsonNormWithToString,
],
));
$this->assertSame(
'{"message":"Testing","context":{"public":{"foo":"fooValue"},"private":{},"withToStringAndJson":["json serialized"],"withToString":"stringified"},"level":100,"level_name":"DEBUG","channel":"test","datetime":"2022-02-22T00:00:00+00:00","extra":{}}'."\n",
$record
);
}
}
class TestJsonNormPublic
{
public $foo = 'fooValue';
}
class TestJsonNormPrivate
{
private $foo = 'fooValue';
}
class TestJsonNormWithToStringAndJson implements JsonSerializable
{
public function jsonSerialize()
{
return ['json serialized'];
}
public function __toString()
{
return 'SHOULD NOT SHOW UP';
}
}
class TestJsonNormWithToString
{
public function __toString()
{
return 'stringified';
}
}

View File

@@ -364,8 +364,10 @@ class NormalizerFormatterTest extends TestCase
$record = $this->getRecord(context: ['exception' => $e]);
$result = $formatter->format($record);
// See https://github.com/php/php-src/issues/8810 fixed in PHP 8.2
$offset = PHP_VERSION_ID >= 80200 ? 13 : 11;
$this->assertSame(
__FILE__.':'.(__LINE__-9),
__FILE__.':'.(__LINE__ - $offset),
$result['context']['exception']['trace'][0]
);
}