Description
TL;DR; There should be an easy way to see whether deprecation errors occur in production, so you can know whether you're really ready for Symfony 3.
We are busy updating our applications to Symfony 3. The simple approach of this problem would be to
- Fix the most obvious deprecations that turn up in the dev bar.
- Update to Symfony 3.
- Test.
However, some of our applications are rather big. What we would like to do is
- First fix the most obvious deprecations that turn up in the dev bar
- Turn on the logging of deprecation errors to the server logs.
- Read deprecation errors from the logs & fix them.
- Update to Symfony 3.
- Test.
For the first step the developer experience is rather good, so thanks for that! The 3th and 4th step should also be no problem. My problem is with the second step, logging them.
When the initial deprecations were added, all deprecations were logged and people ran out of diskspace. The logging should clearly not be on by default. But right now they have been turned off rather rigorously. How can we still log them to the server log?
Solution 1: By adding a user land error handler
The first thing I tried was to add a user land error handler. It's rather easy to do this, see this gist.
When I do this, suddenly all deprecation logs dissapear from the toolbar! After a bit of tracing I found that the DebugHandlersListener only injects the logger if the current handler is an error handler. Relevant links to source: injecting logger, injecting exception handler, also injecting exception handler.
Solution one would mean creating a bundle that mimicks the behaviour of the DebugHandlersListener to inject the logger into my error handler, so it can forward it to the one from Symfony. It would also mean that everyone updating a large app has to reinvent this wheel.
Solution 2: Solving it in Symfony
What if we'd add an option to the framework bundle (or another?) log_deprecations
.
framework:
log_deprecations: true # default false
Which could then do something similar to this gist. This would give me the level of DX that I'd expect from Symfony.
Solution 3: Reinstating the ErrorsLoggerListener
The (now deprecated) ErrorsLoggerListener injected the logger in a way that makes it possible to replace the error handler.
Solution 4: The one I've missed?
- Searching for everything in the 30 page upgrade guide isn't really an option for us.
- Our code coverage is increasing, so the PHPUnit deprecations help. But that alone doesn't give us enough confidence to upgrade.
- The upgrade guide only offers the simple approach here.
What is the best way to log the deprecation notices server side? If something already exists, that would be awesome! If someone proposes a possible Symfony side solution, I'd be willing to work towards a PR for the 2.8 (or 2.7?) branch.