Просмотр исходного кода

Fix JSON formatting of resource type, closes #1410

theravel 6 лет назад
Родитель
Сommit
9621075c0f

+ 4 - 0
src/Monolog/Formatter/JsonFormatter.php

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

+ 8 - 0
tests/Monolog/Formatter/JsonFormatterTest.php

@@ -114,6 +114,14 @@ class JsonFormatterTest extends TestCase
         $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 $actual