mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-01 19:00:20 +02:00
Merge branch '2.x'
This commit is contained in:
@@ -188,6 +188,10 @@ class JsonFormatter extends NormalizerFormatter
|
||||
return $data->__toString();
|
||||
}
|
||||
|
||||
if (\get_class($data) === '__PHP_Incomplete_Class') {
|
||||
return new \ArrayObject($data);
|
||||
}
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
@@ -122,7 +122,9 @@ class StreamHandler extends AbstractProcessingHandler
|
||||
}
|
||||
$this->createDir($url);
|
||||
$this->errorMessage = null;
|
||||
set_error_handler([$this, 'customErrorHandler']);
|
||||
set_error_handler(function (...$args) {
|
||||
return $this->customErrorHandler(...$args);
|
||||
});
|
||||
try {
|
||||
$stream = fopen($url, 'a');
|
||||
if ($this->filePermission !== null) {
|
||||
@@ -193,7 +195,9 @@ class StreamHandler extends AbstractProcessingHandler
|
||||
$dir = $this->getDirFromStream($url);
|
||||
if (null !== $dir && !is_dir($dir)) {
|
||||
$this->errorMessage = null;
|
||||
set_error_handler([$this, 'customErrorHandler']);
|
||||
set_error_handler(function (...$args) {
|
||||
return $this->customErrorHandler(...$args);
|
||||
});
|
||||
$status = mkdir($dir, 0777, true);
|
||||
restore_error_handler();
|
||||
if (false === $status && !is_dir($dir) && strpos((string) $this->errorMessage, 'File exists') === false) {
|
||||
|
@@ -274,6 +274,18 @@ class JsonFormatterTest extends TestCase
|
||||
$this->assertEquals('Over 1000 items (2000 total), aborting normalization', $res['context'][0]['...']);
|
||||
}
|
||||
|
||||
public function testCanNormalizeIncompleteObject(): void
|
||||
{
|
||||
$serialized = "O:17:\"Monolog\TestClass\":1:{s:23:\"\x00Monolog\TestClass\x00name\";s:4:\"test\";}";
|
||||
$object = unserialize($serialized);
|
||||
|
||||
$formatter = new JsonFormatter();
|
||||
$record = $this->getRecord(context: ['object' => $object], datetime: new \DateTimeImmutable('2022-02-22 00:00:00'));
|
||||
$result = $formatter->format($record);
|
||||
|
||||
self::assertSame('{"message":"test","context":{"object":{"__PHP_Incomplete_Class_Name":"Monolog\\\\TestClass"}},"level":300,"level_name":"WARNING","channel":"test","datetime":"2022-02-22T00:00:00+00:00","extra":{}}'."\n", $result);
|
||||
}
|
||||
|
||||
public function testEmptyContextAndExtraFieldsCanBeIgnored()
|
||||
{
|
||||
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, true, true);
|
||||
|
Reference in New Issue
Block a user