Skip to content

Commit

Permalink
Fix JSON formatting of resource type, closes #1410
Browse files Browse the repository at this point in the history
  • Loading branch information
theravel authored and Seldaek committed Dec 20, 2019
1 parent 0d733f9 commit 9621075
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Monolog/Formatter/JsonFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,10 @@ protected function normalize($data, $depth = 0)
return $this->normalizeException($data);
}

if (is_resource($data)) {
return parent::normalize($data);
}

return $data;
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Monolog/Formatter/JsonFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ public function testDefFormatWithThrowable()
$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
Expand Down

0 comments on commit 9621075

Please sign in to comment.