Skip to content

[Console] Document the silent verbosity level #20247

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions components/console/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,17 @@ You can suppress output with:

.. code-block:: terminal

# suppresses all output, including errors
$ php application.php list --silent

# suppresses all output except errors
$ php application.php list --quiet
$ php application.php list -q

.. versionadded:: 7.2

The ``--silent`` option was introduced in Symfony 7.2.

You can get more verbose messages (if this is supported for a command)
with:

Expand Down
7 changes: 6 additions & 1 deletion console/input.rst
Original file line number Diff line number Diff line change
Expand Up @@ -446,12 +446,17 @@ The Console component adds some predefined options to all commands:

* ``--verbose``: sets the verbosity level (e.g. ``1`` the default, ``2`` and
``3``, or you can use respective shortcuts ``-v``, ``-vv`` and ``-vvv``)
* ``--quiet``: disables output and interaction
* ``--silent``: disables all output and interaction, including errors
* ``--quiet``: disables output and interaction, but errors are still displayed
* ``--no-interaction``: disables interaction
* ``--version``: outputs the version number of the console application
* ``--help``: displays the command help
* ``--ansi|--no-ansi``: whether to force of disable coloring the output

.. versionadded:: 7.2

The ``--silent`` option was introduced in Symfony 7.2.

When using the ``FrameworkBundle``, two more options are predefined:

* ``--env``: sets the Kernel configuration environment (defaults to ``APP_ENV``)
Expand Down
23 changes: 20 additions & 3 deletions console/verbosity.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ messages, but you can control their verbosity with the ``-q`` and ``-v`` options

.. code-block:: terminal

# do not output any message (not even the command result messages)
# suppress all output, including errors
$ php bin/console some-command --silent

# suppress all output (even the command result messages) but display errors
$ php bin/console some-command -q
$ php bin/console some-command --quiet

Expand All @@ -23,13 +26,18 @@ messages, but you can control their verbosity with the ``-q`` and ``-v`` options
# display all messages (useful to debug errors)
$ php bin/console some-command -vvv

.. versionadded:: 7.2

The ``--silent`` option was introduced in Symfony 7.2.

The verbosity level can also be controlled globally for all commands with the
``SHELL_VERBOSITY`` environment variable (the ``-q`` and ``-v`` options still
have more precedence over the value of ``SHELL_VERBOSITY``):

===================== ========================= ===========================================
Console option ``SHELL_VERBOSITY`` value Equivalent PHP constant
===================== ========================= ===========================================
``--silent`` ``-2`` ``OutputInterface::VERBOSITY_SILENT``
``-q`` or ``--quiet`` ``-1`` ``OutputInterface::VERBOSITY_QUIET``
(none) ``0`` ``OutputInterface::VERBOSITY_NORMAL``
``-v`` ``1`` ``OutputInterface::VERBOSITY_VERBOSE``
Expand Down Expand Up @@ -58,7 +66,7 @@ level. For example::
'Password: '.$input->getArgument('password'),
]);

// available methods: ->isQuiet(), ->isVerbose(), ->isVeryVerbose(), ->isDebug()
// available methods: ->isSilent(), ->isQuiet(), ->isVerbose(), ->isVeryVerbose(), ->isDebug()
if ($output->isVerbose()) {
$output->writeln('User class: '.get_class($user));
}
Expand All @@ -73,10 +81,19 @@ level. For example::
}
}

When the quiet level is used, all output is suppressed as the default
.. versionadded:: 7.2

The ``isSilent()`` method was introduced in Symfony 7.2.

When the silent or quiet level are used, all output is suppressed as the default
:method:`Symfony\\Component\\Console\\Output\\Output::write` method returns
without actually printing.

.. tip::

When using the ``silent`` verbosity, errors won't be displayed in the console
but they will still be logged through the :doc:`Symfony logger </logging>` integration.

.. tip::

The MonologBridge provides a :class:`Symfony\\Bridge\\Monolog\\Handler\\ConsoleHandler`
Expand Down
Loading