Verbosity Levels
Warning: You are browsing the documentation for Symfony 2.x, which is no longer maintained.
Read the updated version of this page for Symfony 7.2 (the current stable version).
2.3
The VERBOSITY_VERY_VERBOSE
and VERBOSITY_DEBUG
constants were introduced
in version 2.3
The console has five verbosity levels. These are defined in the 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 |
It is possible to print a message in a command for only a specific verbosity level. For example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
// ...
class CreateUserCommand extends Command
{
// ...
public function execute(InputInterface $input, OutputInterface $output)
{
$user = new User(...);
$output->writeln(array(
'Username: '.$input->getArgument('username'),
'Password: '.$input->getArgument('password'),
));
// the user class is only printed when the verbose verbosity level is used
if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
$output->writeln('User class: '.get_class($user));
}
// alternatively you can pass the verbosity level to writeln()
$output->writeln(
'Will only be printed in verbose mode or higher',
OutputInterface::VERBOSITY_VERBOSE
);
}
}
2.8
The ability to pass the verbosity level to the writeln()
method was
introduced in Symfony 2.8.
There are also more semantic methods you can use to test for each of the verbosity levels:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
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. Output)
in order to keep backward compatibility.
When the quiet level is used, all output is suppressed as the default write() method returns without actually printing.
Tip
The MonologBridge provides a ConsoleHandler class that allows you to display messages on the console. This is cleaner than wrapping your output calls in conditions. For an example use in the Symfony Framework, see How to Configure Monolog to Display Console Messages.
Tip
The full exception stacktrace is printed if the VERBOSITY_VERBOSE
level or above is used.