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

Merge branch '2.x'

This commit is contained in:
Jordi Boggiano
2023-10-27 15:24:31 +02:00
4 changed files with 25 additions and 5 deletions

View File

@@ -162,7 +162,7 @@ class LineFormatter extends NormalizerFormatter
do { do {
$depth++; $depth++;
if ($depth > $this->maxNormalizeDepth) { if ($depth > $this->maxNormalizeDepth) {
$str .= '\n[previous exception] Over ' . $this->maxNormalizeDepth . ' levels deep, aborting normalization'; $str .= "\n[previous exception] Over " . $this->maxNormalizeDepth . ' levels deep, aborting normalization';
break; break;
} }

View File

@@ -206,6 +206,9 @@ class NormalizerFormatter implements FormatterInterface
if ($data instanceof \JsonSerializable) { if ($data instanceof \JsonSerializable) {
/** @var null|scalar|array<mixed[]|scalar|null> $value */ /** @var null|scalar|array<mixed[]|scalar|null> $value */
$value = $data->jsonSerialize(); $value = $data->jsonSerialize();
} elseif (\get_class($data) === '__PHP_Incomplete_Class') {
$accessor = new \ArrayObject($data);
$value = (string) $accessor['__PHP_Incomplete_Class_Name'];
} elseif (method_exists($data, '__toString')) { } elseif (method_exists($data, '__toString')) {
/** @var string $value */ /** @var string $value */
$value = $data->__toString(); $value = $data->__toString();

View File

@@ -123,11 +123,14 @@ class StreamHandler extends AbstractProcessingHandler
$this->createDir($url); $this->createDir($url);
$this->errorMessage = null; $this->errorMessage = null;
set_error_handler([$this, 'customErrorHandler']); set_error_handler([$this, 'customErrorHandler']);
$stream = fopen($url, 'a'); try {
if ($this->filePermission !== null) { $stream = fopen($url, 'a');
@chmod($url, $this->filePermission); if ($this->filePermission !== null) {
@chmod($url, $this->filePermission);
}
} finally {
restore_error_handler();
} }
restore_error_handler();
if (!is_resource($stream)) { if (!is_resource($stream)) {
$this->stream = null; $this->stream = null;

View File

@@ -402,6 +402,20 @@ class NormalizerFormatterTest extends TestCase
); );
} }
public function testCanNormalizeIncompleteObject(): void
{
$serialized = "O:17:\"Monolog\TestClass\":1:{s:23:\"\x00Monolog\TestClass\x00name\";s:4:\"test\";}";
$object = unserialize($serialized);
$formatter = new NormalizerFormatter();
$record = $this->getRecord(context: ['object' => $object]);
$result = $formatter->format($record);
$this->assertEquals([
'__PHP_Incomplete_Class' => 'Monolog\\TestClass',
], $result['context']['object']);
}
private function throwHelper($arg) private function throwHelper($arg)
{ {
throw new \RuntimeException('Thrown'); throw new \RuntimeException('Thrown');