|
| 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`. |
0 commit comments