When working with certain third-party services, you may need your Symfony application to produce logs in JSON format for easier integration. Fortunately, this is straightforward to achieve with Symfony's Monolog integration.
However, when running some console commands, they might generate output on both
the stdout
and stderr
streams. This is problematic if the third-party
service expects only JSON log contents and encounters this unstructured data.
Thankfully, Symfony provides a feature to control the verbosity of console commands.
Add the -q
or --quiet
option to your command (or set the SHELL_VERBOSITY
env var to -1
) and you won't get any output when running the command.
The only things not suppressed by the quiet
verbosity are errors and exceptions.
To address this, in Symfony 7.2 we're introducing a new verbosity level called
silent
(equivalent to the SHELL_VERBOSITY=-2
env var). This new level
suppresses all output, including errors and exceptions:
1 2 3 4 5
# suppresses all output
$ php bin/console some-command --silent
# suppresses all output except errors
$ php bin/console some-command --quiet
Note: this will break commands that already use those options, be careful when you upgrade