1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-22 00:56:08 +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:
Thomas Ploch
2014-12-16 13:23:04 +01:00
parent 2d192b0567
commit dca8f5841f
3 changed files with 55 additions and 71 deletions

View File

@@ -108,8 +108,8 @@ class NormalizerFormatter implements FormatterInterface
if (isset($frame['file'])) {
$data['trace'][] = $frame['file'].':'.$frame['line'];
} else {
$frame = $this->convertResourceArgs($frame);
$data['trace'][] = json_encode($frame);
// We should again normalize the frames, because it might contain invalid items
$data['trace'][] = $this->toJson($this->normalize($frame), true);
}
}
@@ -137,29 +137,4 @@ class NormalizerFormatter implements FormatterInterface
return json_encode($data);
}
/**
* This method checks recursively for resource args inside the frame, since json_encode is choking on them.
*
* @param array $frame Reference to current frame
* @return array
*/
private function convertResourceArgs(array $frame)
{
foreach ($frame as $key => $item) {
if (is_scalar($item)) {
continue;
}
if (is_resource($item)) {
$frame[$key] = (string) $item;
}
if (is_array($item)) {
$frame[$key] = $this->convertResourceArgs($item);
}
}
return $frame;
}
}