Symfony2 is not logging exceptions thrown inside custom command
-
02-07-2021 - |
Question
When an error occurs during a normal http request, Symfony2 logs everything (depending on your logging level) and you can see it in dev.log or app.log.
But when you get an error during the execution of a custom command, it doesn't log anything. It just shows a red message in standard output, that doesn't even have a backtrace.
What can I do to have all errors logged, like in the first case?
Solution 2
I had to do this on my own, Symfony2 won't do it.
Create a BaseCommand to extend that catches all errors and exceptions and logs them.
OTHER TIPS
When you add --verbose
option when run the command you should see backtrace.
I imagine that you can just catch \Exception
and use monolog logger from the container (command have access to DIC) if you want.
I think you can do it in other way too if its needed for example by
extending Symfony\Component\Console\Application
class and method renderException
and log errors there but I never do that really, just see that Command/Application API should allow for that.