1
0
mirror of https://github.com/Seldaek/monolog.git synced 2025-10-22 09:06:10 +02:00

Catch json_encode recursion error

This commit is contained in:
Benjamin Grandfond
2012-12-21 23:12:43 +01:00
parent 52b454f890
commit 0945fcdccb
2 changed files with 49 additions and 0 deletions

View File

@@ -54,16 +54,24 @@ class WildfireFormatter extends NormalizerFormatter
$record = $this->normalize($record);
$message = array('message' => $record['message']);
$handleError = false;
if ($record['context']) {
$message['context'] = $record['context'];
$handleError = true;
}
if ($record['extra']) {
$message['extra'] = $record['extra'];
$handleError = true;
}
if (count($message) === 1) {
$message = reset($message);
}
// Handle json_encode recursion error
if ($handleError) {
set_error_handler(function () { });
}
// Create JSON object describing the appearance of the message in the console
$json = json_encode(array(
array(
@@ -75,6 +83,10 @@ class WildfireFormatter extends NormalizerFormatter
$message,
));
if ($handleError) {
restore_error_handler();
}
// The message itself is a serialization of the above JSON object + it's length
return sprintf(
'%s|%s|',