New in Symfony 3.3: Automatic Console logging

Warning: This post is about an unsupported Symfony version. Some of this information may be out of date. Read the most recent Symfony Docs.
Contributed by
Robin Chalas
and James Halsall
in #21003.
The Console component doesn't provide any logging capabilities out of the box because you normally run console commands yourself and observe the output. However, there are cases when you might need logging; for example, when running console commands unattended, such as from Cron jobs or deployment scripts.
In Symfony 3.2 you had to create your own event listener or subscriber to
subscribe to the console.exception
event and log the exception details.
In Symfony 3.3 we decided to enable automatic exception logging for console
commands.
Therefore, when an exception occurs during the execution of a command, you'll see a message like the following in your log file:
1 2 3 4 5
[2017-02-15 09:34:42] app.ERROR: Exception thrown while running command:
"cache:clear -vvv". Message: "An error occured!" {"exception":"[object]
(RuntimeException(code: 0): An error occured! at vendor/symfony/symfony/
src/Symfony/Bundle/FrameworkBundle/Command/CacheClearCommand.php:61)",
"command":"cache:clear -vvv","message":"An error occured!"} []
In addition to logging exceptions, the new subscriber also listens to the
console.terminate
event to add a log message whenever a command doesn't
finish with the 0
exit status.
Help the Symfony project!
As with any Open-Source project, contributing code or documentation is the most common way to help, but we also have a wide range of sponsoring opportunities.
Comments
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.
So to integrate with Logstash, it is a matter of configuring your logger for that (as any other log message in Symfony). and Monolog has some features for that