You are browsing the documentation for Symfony 2.8 which is not maintained anymore.
Consider upgrading your projects to Symfony 5.2.
Verbosity Levels
Verbosity Levels¶
New in 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
Symfony\Component\Console\Output\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:
// ...
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
);
}
}
New in version 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:
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. Symfony\Component\Console\Output\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 Symfony\Bridge\Monolog\Handler\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.
This work, including the code samples, is licensed under a Creative Commons BY-SA 3.0 license.