Skip to content

Commit 9621075

Browse files
theravelSeldaek
authored andcommitted
Fix JSON formatting of resource type, closes #1410
1 parent 0d733f9 commit 9621075

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/Monolog/Formatter/JsonFormatter.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,10 @@ protected function normalize($data, $depth = 0)
165165
return $this->normalizeException($data);
166166
}
167167

168+
if (is_resource($data)) {
169+
return parent::normalize($data);
170+
}
171+
168172
return $data;
169173
}
170174

tests/Monolog/Formatter/JsonFormatterTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,14 @@ public function testDefFormatWithThrowable()
114114
$this->assertContextContainsFormattedException($formattedThrowable, $message);
115115
}
116116

117+
public function testDefFormatWithResource()
118+
{
119+
$formatter = new JsonFormatter(JsonFormatter::BATCH_MODE_JSON, false);
120+
$record = $this->getRecord();
121+
$record['context'] = array('field_resource' => curl_init());
122+
$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));
123+
}
124+
117125
/**
118126
* @param string $expected
119127
* @param string $actual

0 commit comments

Comments
 (0)