Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json_encode recursion detected warning #137

Merged
merged 1 commit into from
Jan 6, 2013

Conversation

benja-M-1
Copy link
Contributor

@stof
Copy link
Contributor

stof commented Dec 19, 2012

This code is wrong as it will never log the context

@stof
Copy link
Contributor

stof commented Dec 19, 2012

A proper fix would be to handle recursion in the NormalizerFormatter

@Seldaek
Copy link
Owner

Seldaek commented Dec 19, 2012

Yeah the problem is that whatever is passed in the context array has a recursive reference somewhere and that blows up json_encode. Handling recursion is gonna suck and make it slower though, but I guess we have no choice.

@benja-M-1
Copy link
Contributor Author

I think that @schmittjoh's serializer handles that case, we may take inspiration from it or even use it ?

@Seldaek
Copy link
Owner

Seldaek commented Dec 21, 2012

@benja-M-1 the serializer is a bit overbloated/overkill for the use case of logging IMO. This should be as fast as possible ideally. I wish json_encode had a flag to ignore recursion.

@benja-M-1
Copy link
Contributor Author

Yes I do agree it's an overkill. I will try to do something today

@Seldaek
Copy link
Owner

Seldaek commented Dec 21, 2012

Actually.. json_encode simply triggers a warning and then returns null where the recursion occurred. So it's maybe enough to do a nasty @json_encode or to register a custom error handler (not sure what's the fastest). It could be done only when the context/extra keys aren't empty to avoid slowing down normal messages.

}
if (count($message) === 1) {
$message = reset($message);
}

// Handle json_encode recursion error
if ($handleError) {
set_error_handler(function () { });
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what to do here. Should it raise a new error if it's the json_encode that raised the error first?

@benja-M-1
Copy link
Contributor Author

@Seldaek do I have something else to do?

@Seldaek Seldaek merged commit 0945fcd into Seldaek:master Jan 6, 2013
@Seldaek
Copy link
Owner

Seldaek commented Jan 6, 2013

Nope, merged and refactored things a bit so that it's applied to all formatters and not just the wildfire case.

@benja-M-1 benja-M-1 deleted the patch-wildfire-formatter branch January 6, 2013 20:40
@benja-M-1
Copy link
Contributor Author

When do you plan to create a new tag with, at least, this fix?

@Seldaek
Copy link
Owner

Seldaek commented Jan 7, 2013

This week sometime. I'm trying to merge just a couple more PRs and then release.

@benja-M-1
Copy link
Contributor Author

Great, thank you! Keep up the good work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

trigger_error and logging produce Warning
3 participants