1

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?

2 Answers 2

2

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.