1
1
Verbosity Levels
2
2
================
3
3
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
+ ===================== ========================= ===========================================
16
39
17
40
It is possible to print a message in a command for only a specific verbosity
18
41
level. For example::
@@ -31,45 +54,19 @@ level. For example::
31
54
'Password: '.$input->getArgument('password'),
32
55
));
33
56
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() ) {
36
59
$output->writeln('User class: '.get_class($user));
37
60
}
38
61
39
- // alternatively you can pass the verbosity level to writeln()
62
+ // alternatively you can pass the verbosity level PHP constant to writeln()
40
63
$output->writeln(
41
64
'Will only be printed in verbose mode or higher',
42
65
OutputInterface::VERBOSITY_VERBOSE
43
66
);
44
67
}
45
68
}
46
69
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
-
73
70
When the quiet level is used, all output is suppressed as the default
74
71
:method: `Symfony\\ Component\\ Console\\ Output\\ Output::write ` method returns
75
72
without actually printing.
0 commit comments