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?

Was it helpful?

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top