Skip to content

Reworded the console verbosity article to explain SHELL_VERBOSITY too #8896

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

Closed
wants to merge 2 commits into from
Closed
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
79 changes: 38 additions & 41 deletions console/verbosity.rst
Original file line number Diff line number Diff line change
@@ -1,18 +1,41 @@
Verbosity Levels
================

The console has five verbosity levels. These are defined in the
:class:`Symfony\\Component\\Console\\Output\\OutputInterface`:

=========================================== ================================== =====================
Value Meaning Console option
=========================================== ================================== =====================
``OutputInterface::VERBOSITY_QUIET`` Do not output any messages ``-q`` or ``--quiet``
``OutputInterface::VERBOSITY_NORMAL`` The default verbosity level (none)
``OutputInterface::VERBOSITY_VERBOSE`` Increased verbosity of messages ``-v``
``OutputInterface::VERBOSITY_VERY_VERBOSE`` Informative non essential messages ``-vv``
``OutputInterface::VERBOSITY_DEBUG`` Debug messages ``-vvv``
=========================================== ================================== =====================
Console commands have different verbosity levels, which determine the messages
displayed in their output. By default, commands display only the most useful
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)
$ php bin/console some-command -q
$ php bin/console some-command --quiet

# normal behavior, no option required (display only the useful messages)
$ php bin/console some-command

# increase verbosity of messages
$ php bin/console some-command -v

# display also the informative non essential messages
$ php bin/console some-command -vv

# display all messages (useful to debug errors)
$ php bin/console some-command -vvv

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
===================== ========================= ===========================================
``-q`` or ``--quiet`` ``-1`` ``OutputInterface::VERBOSITY_QUIET``
(none) ``0`` ``OutputInterface::VERBOSITY_NORMAL``
``-v`` ``1`` ``OutputInterface::VERBOSITY_VERBOSE``
``-vv`` ``2`` ``OutputInterface::VERBOSITY_VERY_VERBOSE``
``-vvv`` ``3`` ``OutputInterface::VERBOSITY_DEBUG``
===================== ========================= ===========================================

It is possible to print a message in a command for only a specific verbosity
level. For example::
Expand All @@ -31,45 +54,19 @@ level. For example::
'Password: '.$input->getArgument('password'),
));

// the user class is only printed when the verbose verbosity level is used
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
// available methods: ->isQuiet(), ->isVerbose(), ->isVeryVerbose(), ->isDebug()
if ($output->isVerbose()) {
$output->writeln('User class: '.get_class($user));
}

// alternatively you can pass the verbosity level to writeln()
// alternatively you can pass the verbosity level PHP constant to writeln()
$output->writeln(
'Will only be printed in verbose mode or higher',
OutputInterface::VERBOSITY_VERBOSE
);
}
}

There are also more semantic methods you can use to test for each of the
verbosity levels::

if ($output->isQuiet()) {
// ...
}

if ($output->isVerbose()) {
// ...
}

if ($output->isVeryVerbose()) {
// ...
}

if ($output->isDebug()) {
// ...
}

.. note::

These semantic methods are defined in the ``OutputInterface`` starting from
Symfony 3.0. In previous Symfony versions they are defined in the different
implementations of the interface (e.g. :class:`Symfony\\Component\\Console\\Output\\Output`)
in order to keep backward compatibility.

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