mirror of
https://github.com/Seldaek/monolog.git
synced 2025-08-06 13:16:39 +02:00
Normalize frames for trace items since they can contain invalid data.
Refs https://github.com/Seldaek/monolog/pull/474/files The fix in the previous PR did not take into account that there might be object wrapped resources that would break json_encode, so the best solution would be normalizing those frames again. @Seldaek Sorry for the inconvenience, but our graylog is still ramming up with those json_encode error messages.
This commit is contained in:
@@ -182,50 +182,6 @@ class GelfMessageFormatterTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals('pair', $message_array['_EXTkey']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers Monolog\Formatter\GelfMessageFormatter::format
|
||||
*/
|
||||
public function testExceptionObjectWithResourceTrace()
|
||||
{
|
||||
if (defined('HHVM_VERSION')) {
|
||||
$this->markTestSkipped('Not supported in HHVM since it detects errors differently');
|
||||
}
|
||||
|
||||
// This happens i.e. in React promises or Guzzle streams where stream wrappers are registered
|
||||
// and no file or line are included in the trace because it's treated as internal function
|
||||
set_error_handler(function ($errno, $errstr, $errfile, $errline ) {
|
||||
throw new \ErrorException($errstr, 0, $errno, $errfile, $errline);
|
||||
});
|
||||
|
||||
try {
|
||||
$resource = fopen('php://memory', '+w');
|
||||
// Just do something stupid with a resource as argument
|
||||
strpos($resource, 'FOO');
|
||||
} catch (\Exception $e) {
|
||||
}
|
||||
|
||||
// restore the error handler
|
||||
restore_error_handler();
|
||||
|
||||
$formatter = new GelfMessageFormatter();
|
||||
$record = array(
|
||||
'level' => Logger::ERROR,
|
||||
'level_name' => 'ERROR',
|
||||
'channel' => 'meh',
|
||||
'context' => array('from' => 'logger', 'exception' => $e),
|
||||
'datetime' => new \DateTime("@0"),
|
||||
'extra' => array(),
|
||||
'message' => 'log'
|
||||
);
|
||||
|
||||
$message = $formatter->format($record);
|
||||
|
||||
$this->assertRegExp(
|
||||
'%\\\\"resource\\\\":\\\\"Resource id #\d+\\\\"%',
|
||||
$message->getAdditional('ctxt_exception')
|
||||
);
|
||||
}
|
||||
|
||||
private function isLegacy()
|
||||
{
|
||||
return interface_exists('\Gelf\IMessagePublisher');
|
||||
|
Reference in New Issue
Block a user