How is it possible to send email with log when something wrong in console command? Currently I've configured my app to send emails from web interface and it works correctly. Swiftmailer spool is disabled. My config is:
monolog:
handlers:
main:
type: fingers_crossed
action_level: critical
handler: grouped
grouped:
type: group
members: [streamed, buffered]
streamed:
type: stream
path: "%kernel.logs_dir%/%kernel.environment%.log"
level: debug
buffered:
type: buffer
handler: swift
swift:
type: swift_mailer
from_email: info@site.com
to_email: username@site.com
subject: An Error Occurred!
level: debug
When I try to execute php app/console test:exception-command -e prod
which throws exception no email sends.
I had the same problem, and after a couple of attempts I got a solution. The problem is the spool in swiftmailer, it was configured as memory so I changed it to file
Then I called the logger in the command
And after the command I called the swiftmailer command to send pending emails
For Symfony < 2.3
There is another possibility, overwrite the Application class the following class could help, this application class activates logger for the console and logs autoexists
Then use it in app/console
At least remove app/cache/* directories app/console cache:clear was not enough
It should send emails with the spool disabled in your swiftmailer config, this should cause emails to be sent out immediately rather than be spooled and your command uses the logger.
If you want to use the memory spool you can flush the queue in your command's execute methods.
Reference: http://symfony.com/doc/current/cookbook/console/sending_emails.html#using-memory-spooling
If you are wanting to log Uncaught Exceptions you will have to configure a console event to work with the logger.
http://symfony.com/doc/current/cookbook/console/logging.html#enabling-automatic-exceptions-logging