-
-
Notifications
You must be signed in to change notification settings - Fork 338
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
Debugging Components: Info for PHP #2526
Conversation
Uplink03
commented
Jan 25, 2025
Q | A |
---|---|
Bug fix? | yes/no |
New feature? | yes/no |
Issues | Fix #... |
License | MIT |
To debug your PHP code, you can inject a `private LoggerInterface $logger` in your `__construct`. | ||
Then you can use `$this->logger->debug('Message', ['var' => $var]);` and see the output in `var/log/dev.log`. | ||
`dump` won't display anything anywhere (not even the debug toolbar). | ||
`dd` will display in your browser, but will also deadlock your component - you cannot dismiss it and continue working. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the same thing in a webpage. dd
means dump and die
.
@@ -3715,6 +3715,11 @@ Debugging Components | |||
Need to list or debug some component issues. | |||
The `Twig Component debug command`_ can help you. | |||
|
|||
To debug your PHP code, you can inject a `private LoggerInterface $logger` in your `__construct`. | |||
Then you can use `$this->logger->debug('Message', ['var' => $var]);` and see the output in `var/log/dev.log`. | |||
`dump` won't display anything anywhere (not even the debug toolbar). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not true.
During the first render, dumps are shown either in the template or in the debug toolbar.
On following request they are shown on the profiler, like any AJAX request.
To debug your PHP code, you can inject a `private LoggerInterface $logger` in your `__construct`. | ||
Then you can use `$this->logger->debug('Message', ['var' => $var]);` and see the output in `var/log/dev.log`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure this is really needed, as it applies to any component / service in Symfony apps (and you can inject a Logger with a lot of other methods,) .
We could send the user towards the documentation pages on logging, but then it would not be really about debugging.
This was meant as a quick mention of deficiencies when debugging the component in the browser. I didn't put much thought into it, and I'm not really sure how I phrase it better. I'll withdraw the PR and come back if I have a better one. |
Thank you for opening the PR and making this effort! 👍 |