Skip to content

Commit d55096e

Browse files
committed
Move Verbosity to a guide article
1 parent 864fccb commit d55096e

File tree

4 files changed

+87
-73
lines changed

4 files changed

+87
-73
lines changed

components/console.rst

-71
Original file line numberDiff line numberDiff line change
@@ -134,77 +134,6 @@ Commands have three lifecycle methods:
134134
It contains the logic you want the command to execute.
135135

136136

137-
.. _verbosity-levels:
138-
139-
Verbosity Levels
140-
~~~~~~~~~~~~~~~~
141-
142-
.. versionadded:: 2.3
143-
The ``VERBOSITY_VERY_VERBOSE`` and ``VERBOSITY_DEBUG`` constants were introduced
144-
in version 2.3
145-
146-
The console has five verbosity levels. These are defined in the
147-
:class:`Symfony\\Component\\Console\\Output\\OutputInterface`:
148-
149-
=========================================== ================================== =====================
150-
Value Meaning Console option
151-
=========================================== ================================== =====================
152-
``OutputInterface::VERBOSITY_QUIET`` Do not output any messages ``-q`` or ``--quiet``
153-
``OutputInterface::VERBOSITY_NORMAL`` The default verbosity level (none)
154-
``OutputInterface::VERBOSITY_VERBOSE`` Increased verbosity of messages ``-v``
155-
``OutputInterface::VERBOSITY_VERY_VERBOSE`` Informative non essential messages ``-vv``
156-
``OutputInterface::VERBOSITY_DEBUG`` Debug messages ``-vvv``
157-
=========================================== ================================== =====================
158-
159-
.. tip::
160-
161-
The full exception stacktrace is printed if the ``VERBOSITY_VERBOSE``
162-
level or above is used.
163-
164-
It is possible to print a message in a command for only a specific verbosity
165-
level. For example::
166-
167-
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
168-
$output->writeln(...);
169-
}
170-
171-
There are also more semantic methods you can use to test for each of the
172-
verbosity levels::
173-
174-
if ($output->isQuiet()) {
175-
// ...
176-
}
177-
178-
if ($output->isVerbose()) {
179-
// ...
180-
}
181-
182-
if ($output->isVeryVerbose()) {
183-
// ...
184-
}
185-
186-
if ($output->isDebug()) {
187-
// ...
188-
}
189-
190-
.. note::
191-
192-
These semantic methods are defined in the ``OutputInterface`` starting from
193-
Symfony 3.0. In previous Symfony versions they are defined in the different
194-
implementations of the interface (e.g. :class:`Symfony\\Component\\Console\\Output\\Output`)
195-
in order to keep backwards compatibility.
196-
197-
When the quiet level is used, all output is suppressed as the default
198-
:method:`Symfony\\Component\\Console\\Output\\Output::write` method returns
199-
without actually printing.
200-
201-
.. tip::
202-
203-
The MonologBridge provides a :class:`Symfony\\Bridge\\Monolog\\Handler\\ConsoleHandler`
204-
class that allows you to display messages on the console. This is cleaner
205-
than wrapping your output calls in conditions. For an example use in
206-
the Symfony Framework, see :doc:`/logging/monolog_console`.
207-
208137

209138
Console Helpers
210139
---------------

components/console/helpers/debug_formatter.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ multiple programs at the same time. When using the
3636
.. tip::
3737

3838
This information is often too verbose to be shown by default. You can use
39-
:ref:`verbosity levels <verbosity-levels>` to only show it when in
39+
:doc:`verbosity levels </console/verbosity>` to only show it when in
4040
debugging mode (``-vvv``).
4141

4242
Starting a Program

console/verbosity.rst

+85
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
Verbosity Levels
2+
================
3+
4+
.. versionadded:: 2.3
5+
The ``VERBOSITY_VERY_VERBOSE`` and ``VERBOSITY_DEBUG`` constants were introduced
6+
in version 2.3
7+
8+
The console has five verbosity levels. These are defined in the
9+
:class:`Symfony\\Component\\Console\\Output\\OutputInterface`:
10+
11+
=========================================== ================================== =====================
12+
Value Meaning Console option
13+
=========================================== ================================== =====================
14+
``OutputInterface::VERBOSITY_QUIET`` Do not output any messages ``-q`` or ``--quiet``
15+
``OutputInterface::VERBOSITY_NORMAL`` The default verbosity level (none)
16+
``OutputInterface::VERBOSITY_VERBOSE`` Increased verbosity of messages ``-v``
17+
``OutputInterface::VERBOSITY_VERY_VERBOSE`` Informative non essential messages ``-vv``
18+
``OutputInterface::VERBOSITY_DEBUG`` Debug messages ``-vvv``
19+
=========================================== ================================== =====================
20+
21+
.. tip::
22+
23+
The full exception stacktrace is printed if the ``VERBOSITY_VERBOSE``
24+
level or above is used.
25+
26+
It is possible to print a message in a command for only a specific verbosity
27+
level. For example::
28+
29+
// ...
30+
class CreateUserCommand extends Command
31+
{
32+
// ...
33+
34+
public function execute(InputInterface $input, OutputInterface $output)
35+
{
36+
$user = new User(...);
37+
38+
$output->writeln(array(
39+
'Username: '.$input->getArgument('username'),
40+
'Password: '.$input->getArgument('password'),
41+
));
42+
43+
// the user class is only printed when the verbose verbosity level is used
44+
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
45+
$output->writeln('User class: '.get_class($user));
46+
}
47+
}
48+
}
49+
50+
There are also more semantic methods you can use to test for each of the
51+
verbosity levels::
52+
53+
if ($output->isQuiet()) {
54+
// ...
55+
}
56+
57+
if ($output->isVerbose()) {
58+
// ...
59+
}
60+
61+
if ($output->isVeryVerbose()) {
62+
// ...
63+
}
64+
65+
if ($output->isDebug()) {
66+
// ...
67+
}
68+
69+
.. note::
70+
71+
These semantic methods are defined in the ``OutputInterface`` starting from
72+
Symfony 3.0. In previous Symfony versions they are defined in the different
73+
implementations of the interface (e.g. :class:`Symfony\\Component\\Console\\Output\\Output`)
74+
in order to keep backwards compatibility.
75+
76+
When the quiet level is used, all output is suppressed as the default
77+
:method:`Symfony\\Component\\Console\\Output\\Output::write` method returns
78+
without actually printing.
79+
80+
.. tip::
81+
82+
The MonologBridge provides a :class:`Symfony\\Bridge\\Monolog\\Handler\\ConsoleHandler`
83+
class that allows you to display messages on the console. This is cleaner
84+
than wrapping your output calls in conditions. For an example use in
85+
the Symfony Framework, see :doc:`/logging/monolog_console`.

logging/monolog_console.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ How to Configure Monolog to Display Console Messages
55
====================================================
66

77
It is possible to use the console to print messages for certain
8-
:ref:`verbosity levels <verbosity-levels>` using the
8+
:doc:`verbosity levels </console/verbosity>` using the
99
:class:`Symfony\\Component\\Console\\Output\\OutputInterface` instance that
1010
is passed when a command gets executed.
1111

0 commit comments

Comments
 (0)