1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-08-03 11:47:38 +02:00

Fix JSON formatting of resource type, closes #1410

This commit is contained in:
theravel
2019-12-10 23:20:58 +01:00
committed by Jordi Boggiano
parent 0d733f9297
commit 9621075c0f
2 changed files with 12 additions and 0 deletions

View File

@@ -165,6 +165,10 @@ class JsonFormatter extends NormalizerFormatter
return $this->normalizeException($data); return $this->normalizeException($data);
} }
if (is_resource($data)) {
return parent::normalize($data);
}
return $data; return $data;
} }

View File

@@ -114,6 +114,14 @@ class JsonFormatterTest extends TestCase
$this->assertContextContainsFormattedException($formattedThrowable, $message); $this->assertContextContainsFormattedException($formattedThrowable, $message);
} }
public function testDefFormatWithResource()
{
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, false);
$record = $this->getRecord();
$record['context'] = array('field_resource' => curl_init());
$this->assertEquals('{"message":"test","context":{"field_resource":"[resource] (curl)"},"level":300,"level_name":"WARNING","channel":"test","datetime":'.json_encode($record['datetime']).',"extra":[]}', $formatter->format($record));
}
/** /**
* @param string $expected * @param string $expected
* @param string $actual * @param string $actual