Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1a06394

Browse files
committed
minor #8896 Reworded the console verbosity article to explain SHELL_VERBOSITY too (javiereguiluz)
This PR was squashed before being merged into the 3.4 branch (closes #8896). Discussion ---------- Reworded the console verbosity article to explain SHELL_VERBOSITY too This fixes #8565. Commits ------- 98b2232 Reworded the console verbosity article to explain SHELL_VERBOSITY too
2 parents 1a4b4b6 + 98b2232 commit 1a06394

File tree

1 file changed

+38
-41
lines changed

1 file changed

+38
-41
lines changed

console/verbosity.rst

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,41 @@
11
Verbosity Levels
22
================
33

4-
The console has five verbosity levels. These are defined in the
5-
:class:`Symfony\\Component\\Console\\Output\\OutputInterface`:
6-
7-
=========================================== ================================== =====================
8-
Value Meaning Console option
9-
=========================================== ================================== =====================
10-
``OutputInterface::VERBOSITY_QUIET`` Do not output any messages ``-q`` or ``--quiet``
11-
``OutputInterface::VERBOSITY_NORMAL`` The default verbosity level (none)
12-
``OutputInterface::VERBOSITY_VERBOSE`` Increased verbosity of messages ``-v``
13-
``OutputInterface::VERBOSITY_VERY_VERBOSE`` Informative non essential messages ``-vv``
14-
``OutputInterface::VERBOSITY_DEBUG`` Debug messages ``-vvv``
15-
=========================================== ================================== =====================
4+
Console commands have different verbosity levels, which determine the messages
5+
displayed in their output. By default, commands display only the most useful
6+
messages, but you can control their verbosity with the ``-q`` and ``-v`` options:
7+
8+
.. code-block:: terminal
9+
10+
# do not output any message (not even the command result messages)
11+
$ php bin/console some-command -q
12+
$ php bin/console some-command --quiet
13+
14+
# normal behavior, no option required (display only the useful messages)
15+
$ php bin/console some-command
16+
17+
# increase verbosity of messages
18+
$ php bin/console some-command -v
19+
20+
# display also the informative non essential messages
21+
$ php bin/console some-command -vv
22+
23+
# display all messages (useful to debug errors)
24+
$ php bin/console some-command -vvv
25+
26+
The verbosity level can also be controlled globally for all commands with the
27+
``SHELL_VERBOSITY`` environment variable (the ``-q`` and ``-v`` options still
28+
have more precedence over the value of ``SHELL_VERBOSITY``):
29+
30+
===================== ========================= ===========================================
31+
Console option ``SHELL_VERBOSITY`` value Equivalent PHP constant
32+
===================== ========================= ===========================================
33+
``-q`` or ``--quiet`` ``-1`` ``OutputInterface::VERBOSITY_QUIET``
34+
(none) ``0`` ``OutputInterface::VERBOSITY_NORMAL``
35+
``-v`` ``1`` ``OutputInterface::VERBOSITY_VERBOSE``
36+
``-vv`` ``2`` ``OutputInterface::VERBOSITY_VERY_VERBOSE``
37+
``-vvv`` ``3`` ``OutputInterface::VERBOSITY_DEBUG``
38+
===================== ========================= ===========================================
1639

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

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

39-
// alternatively you can pass the verbosity level to writeln()
62+
// alternatively you can pass the verbosity level PHP constant to writeln()
4063
$output->writeln(
4164
'Will only be printed in verbose mode or higher',
4265
OutputInterface::VERBOSITY_VERBOSE
4366
);
4467
}
4568
}
4669

47-
There are also more semantic methods you can use to test for each of the
48-
verbosity levels::
49-
50-
if ($output->isQuiet()) {
51-
// ...
52-
}
53-
54-
if ($output->isVerbose()) {
55-
// ...
56-
}
57-
58-
if ($output->isVeryVerbose()) {
59-
// ...
60-
}
61-
62-
if ($output->isDebug()) {
63-
// ...
64-
}
65-
66-
.. note::
67-
68-
These semantic methods are defined in the ``OutputInterface`` starting from
69-
Symfony 3.0. In previous Symfony versions they are defined in the different
70-
implementations of the interface (e.g. :class:`Symfony\\Component\\Console\\Output\\Output`)
71-
in order to keep backward compatibility.
72-
7370
When the quiet level is used, all output is suppressed as the default
7471
:method:`Symfony\\Component\\Console\\Output\\Output::write` method returns
7572
without actually printing.

0 commit comments

Comments
 (0)